我正在尝试合并两个WordPress查询,但效果不如分页。
我想显示今天按评论数排序的所有帖子,然后我想显示按评论数排序的所有帖子(不包括今天的帖子)。
我相信这是分别完成任务的两个查询。但我如何组合这些内容,以便新的查询首先按评论数排序列出今天的帖子,然后按评论数排序列出其余帖子。还有分页。
<?php
$today = getdate();
$args1 = array(
\'post_type\' => \'post\',
\'orderby\' => \'comment_count\',
\'ignore_sticky_posts\' => 1,
\'date_query\' => array(
array(
\'year\' => $today[\'year\'],
\'month\' => $today[\'mon\'],
\'day\' => $today[\'mday\'],
),
),
\'paged\' => $paged,
);
$query1 = new WP_Query( $args1 );
$args2 = array(
\'post_type\' => \'post\',
\'orderby\' => \'comment_count\',
\'ignore_sticky_posts\' => 1,
\'paged\' => $paged,
);
$query2 = new WP_Query( $args2 );
?>
EDIT: 1 //@伯吉尔,我试过你建议的方法。但出现了mysql错误。
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'-5,5\' at line 1]
SELECT SQL_CALC_FOUND_ROWS * FROM ( (SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND ( ( post_date > \'2014-08-27 00:00:00\' ) ) AND wp_posts.post_type = \'post\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\') ORDER BY wp_posts.comment_count DESC LIMIT 1000) UNION ALL (SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND ( ( post_date < \'2014-08-27 00:00:00\' ) ) AND wp_posts.post_type = \'post\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\') ORDER BY wp_posts.comment_count DESC LIMIT 1000 ) ) as combined LIMIT -5,5