按ID问题自定义模板顺序

时间:2018-05-14 11:53:14

标签: mysql wordpress sql-order-by

我正在尝试按照ASC顺序对ID进行排序,我可以在使用单个查询时执行此操作但是在使用数组查询时我无法按照ASC顺序对ID进行排序,我的代码如下所示

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

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

之后
my_list = [1,2,3]

d = {'word': my_list}

1 个答案:

答案 0 :(得分:0)

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.

    }

}

希望这适合你。