Combining two wordpress queries with pagination is not working
I am trying to combine two WordPress queries but it's not working as well as pagination.
I want to display today's all posts sorted by comment count and after that I want to display all posts (excluding today's post) sorted by comment count.
I believe these are the two queries to accomplish task separately. But how can I combines these so that new query lists today's posts first sorted by comment count and then rest of the posts sorted by comment count. And also with pagination.
?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 //
@birgire, I tried the method you suggested. But got this mysql error.
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
Topic merging wp-query pagination Wordpress
Category Web