按时间顺序显示合并的Wordpress查询

时间:2016-01-11 23:15:16

标签: php wordpress

如何首先显示实际的$ first_ids,然后显示$ second_ids。使用此代码,它仍然会对它们进行排序。不确定他们的订单是什么,我猜Wordpress defalt排序?

我想要实现的是我在自定义帖子类型“飞机加油”中的所有帖子中添加了标签“精选”,我想首先显示所有“精选”帖子然后显示其余的帖子。

<?php
// first query
$first_ids = get_posts( array(
    'fields'         => 'ids',
    'posts_per_page' => '999',
    'post_status'    => 'publish',
    'post_type'      => array('aircraft-refueling'),
    'tag' => 'featured'
));

// second query
$second_ids = get_posts( array(
    'fields'         => 'ids',
    'posts_per_page' => '999',
    'post_status'    => 'publish',
    'post_type'      => array('aircraft-refueling'),
    'tag__not_in' => array('592')
));

// merging ids
$post_ids = array_merge( $first_ids, $second_ids);

// the main query
$query = new WP_Query(array(
    'post_type' => 'aircraft-refueling',
    'post__in'  => $post_ids, 
    'paged'     => $paged
));
?>

1 个答案:

答案 0 :(得分:0)

我明白了。合并查询后,在第三个查询中,您必须添加

'orderby' => 'post__in', // Preserve post ID order given in the post__in array (available since Version 3.5).

并将帖子按照从合并的帖子数组中检索的顺序排列。