最合适的回答,由SO网友:Peter K. 整理而成
解决问题的灵感来自this 线
其想法是创建单独的查询(无序以节省时间,因为在这个阶段不需要排序),以获得符合条件的帖子ID;然后使用这些ID并以这些ID为标准运行最终查询,以获得完整的帖子(已排序以及此阶段的所有内容)。这样的代码如下所示:
$ids1 = get_posts(array(
\'fields\' => \'ids\',
\'post_type\' => \'frontpage\',
\'posts_per_page\' => -1,
\'date_query\' => array(
array(
\'year\' => date(\'Y\', $date),
\'month\' => date(\'m\', $date),
\'day\' => date(\'d\', $date),
),
),
\'tax_query\' => array(
array(
\'taxonomy\' => \'newspaper_genre\',
\'field\' => \'term_id\',
\'terms\' => array(
7670,
7674,
7682,
7684,
7686,
8099,
8101,
),
\'operator\' => \'NOT IN\',
),
),
));
$ids2 = get_posts(array(
\'fields\' => \'ids\',
\'post_type\' => \'frontpage\',
\'posts_per_page\' => -1,
\'date_query\' => array(
array(
\'year\' => date(\'Y\', $date),
\'month\' => date(\'m\', $date),
),
),
\'tax_query\' => array(
array(
\'taxonomy\' => \'newspaper_genre\',
\'field\' => \'term_id\',
\'terms\' => array(
7682,
8099,
8101,
),
\'operator\' => \'IN\',
),
),
));
$ids3 = get_posts(array(
\'fields\' => \'ids\',
\'post_type\' => \'frontpage\',
\'posts_per_page\' => -1,
\'date_query\' => array(
array(
\'after\' => array(
\'year\' => date(\'Y\', $date_minus_five),
\'month\' => date(\'m\', $date_minus_five),
\'day\' => date(\'d\', $date_minus_five),
),
\'before\' => array(
\'year\' => date(\'Y\', $date),
\'month\' => date(\'m\', $date),
\'day\' => date(\'d\', $date),
),
\'inclusive\' => true,
),
),
\'tax_query\' => array(
array(
\'taxonomy\' => \'newspaper_genre\',
\'field\' => \'term_id\',
\'terms\' => array(
7674,
7684,
7686,
),
\'operator\' => \'IN\',
),
),
));
$query = get_posts(array(
\'include\' => array_merge($ids1, $ids2, $ids3),
\'post_type\' => \'frontpage\',
\'orderby\' => array(
\'meta_value_num\' => \'ASC\',
\'date\' => \'ASC\',
),
\'meta_key\' => \'frontpage_order\',
));