enter image description here

This question is an exact duplicate of:

  • Why WordPress WP_Query has different `posts_per_page` under public `query` and `query_vars`

Here’s what I have in search.php file:

$category_blog = get_category_by_slug('blog');
$category_review = get_category_by_slug('review');
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$search_query = get_search_query();
$the_posts = new WP_Query(array(
  'category__in' => array( $category_blog->term_id,  $category_review->term_id),
  's' => $search_query,
  'paged' => $paged,
  'posts_per_page' => 10,
  'post_type' => 'post',

And you can check the output below:

It’s messing with the WordPress pagination since I got this sql:

SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND (
wp_term_relationships.term_taxonomy_id IN (5,7)
) AND wp_posts.post_title LIKE ‘%firefox%’ AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) GROUP BY wp_posts.ID ORDER BY wp_posts.post_title LIKE ‘%firefox%’ DESC, wp_posts.post_date DESC LIMIT 0, 999999999′

When I remove 's' => $search_query, I would get the same posts_per_page under the two public properties:

I have no idea what’s going on here. Any suggest?

Read more here: WordPress WP_Query has different `posts_per_page` under public `query` and `query_vars` [duplicate]


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: