自定义模板按id排序问题

jrcvhitl  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(329)

我正在尝试按asc顺序按id排序post,我可以在使用单个查询时这样做,但在使用数组查询时,我取消了按asc顺序按id排序post的比例我的代码如下所示

<?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>
q35jwt9p

q35jwt9p1#

按类别名称的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.

    }

}

希望这对你有用。

相关问题