更好的方法是使用三个查询。前两个查询检索post ID,第三个查询按ID查询post。
// first query
$first_ids = get_posts( array(
\'fields\' => \'ids\',
\'posts_per_page\' => \'10\',
\'post_status\' => \'publish\',
\'post_type\' => array(\'news\',\'partners\'),
\'orderby\' => \'date\',
\'order\' => \'DESC\'
));
// second query
$second_ids = get_posts( array(
\'fields\' => \'ids\',
\'posts_per_page\' => \'10\',
\'post_status\' => \'publish\',
\'post_type\' => array(\'post\'),
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'tax_query\' => array(array(
\'taxonomy\' => \'tax\',
\'field\' => \'term_id\',
\'terms\' => array(5)
))
));
// merging ids
$post_ids = array_merge( $first_ids, $second_ids);
// the main query
$query = new WP_Query(array(
\'post_type\' => \'any\',
\'post__in\' => $post_ids,
\'orderby\' => \'date\',
\'order\' => \'DESC\'
));
if( $query->have_posts() ):
// here you go
endif;