Mysql 按id发布的自定义模板订单

Mysql 按id发布的自定义模板订单,mysql,wordpress,sql-order-by,Mysql,Wordpress,Sql Order By,我正在尝试按ASC顺序按ID对帖子进行排序,当我使用单个查询时,我能够做到这一点,但当使用数组查询时,我将取消按ASC顺序按ID对帖子进行排序,我的代码如下所示 <?php $ourCurrentPage = get_query_var('paged'); $newposts = new WP_Query(array( 'category_name' => 'stock-market-basics', 'orderby' => 'ID

我正在尝试按ASC顺序按ID对帖子进行排序,当我使用单个查询时,我能够做到这一点,但当使用数组查询时,我将取消按ASC顺序按ID对帖子进行排序,我的代码如下所示

  <?php
    $ourCurrentPage = get_query_var('paged');
    $newposts = new WP_Query(array(
    'category_name'  => 'stock-market-basics',
    'orderby'    => 'ID',
    'order'      => 'ASC',
    'paged'      => $ourCurrentPage
    ));
  ?>
  <?php 
    if ($newposts->have_posts()):
    while ($newposts->have_posts()):
    $newposts->the_post();
  ?> 

//一些显示代码和关闭后代码//

  <?php endwhile; else : ?>
    <p><?php esc_html_e( 'Sorry, no results matched your criteria.' ); ?</p>
  <?php endif; ?>

            <li><?php 
              echo paginate_links(array(
                'total' => $newposts->max_num_pages
              ));
            ?></li>



  • 按类别名称查询WordPress

    <?php $args = array(
        'posts_per_page'   => 5,
        'offset'           => 0,
        'category'         => '',
        'category_name'    => '',
        'orderby'          => 'date',
        'order'            => 'DESC',
        'include'          => '',
        'exclude'          => '',
        'meta_key'         => '',
        'meta_value'       => '',
        'post_type'        => 'post',
        'post_mime_type'   => '',
        'post_parent'      => '',
        'author'       => '',
        'author_name'      => '',
        'post_status'      => 'publish',
        'suppress_filters' => true 
    );
    $posts_array = get_posts( $args ); ?>
    
    
    // Custom query.
    $query = new WP_Query( $args );
    
    // Check that we have query results.
    if ( $query->have_posts() ) {
    
        // Start looping over the query results.
        while ( $query->have_posts() ) {
    
            $query->the_post();
    
            // Contents of the queried post results go here.
    
        }
    
    }
    
    
    //自定义查询。
    $query=新的WP\u查询($args);
    //检查我们是否有查询结果。
    如果($query->have_posts()){
    //开始循环查询结果。
    而($query->have_posts()){
    $query->the_post();
    //查询的post结果的内容位于此处。
    }
    }
    

    希望这对您有用。

    您想按ID显示类别查询列表顺序吗?是的,但这是类别的自定义模板。请建议这将是非常有帮助的,请检查我的答案。