假设您引用的是this answer
从该答案中提取问题
$args = array(
\'category_name\' => \'your-category-slug\',
\'posts_per_page\' => 3,
);
$wpse_235685_query = new WP_Query( $args );
然后,要颠倒结果的顺序,需要修改查询
$posts
对象,像这样
$temp_posts = $wpse_235685_query->posts; // store the posts to work with
$wpse_235685_query->posts = array(); // empty the $posts object
$wpse_235685_query->posts = array_reverse($temp_post); // set back the object to use new reverse order
当然,这可以通过去掉这样的临时变量来简化
$wpse_235685_query->posts = array_reverse( $wpse_235685_query->posts );
此代码应介于
if( $wpse_235685_query->have_posts() ) :
还有你的
while( $wpse_235685_query->have_posts() ) :
因此,当查询返回空集时,它不会运行。