I struggle already for a few hours with the posts_per_page ignored in my WP_Query :

[query] => Array
    [post_type] => Array

    [posts_per_page] => 4
    [meta_key] => _touchsize_likes
    [orderby] => meta_value_num
    [order] => DESC

The result has found_posts = 18 and 12 posts in the posts array.

Even if the only parameter set is posts_per_page, the results are wrong.

Checked the query_vars['post_type'], the value is 4. Tried with suppress_filters => true, still no effect.

Any idea ?

  • 1
    Poorly written pre_get_posts action in a plugin or in your theme – Pieter Goosen Sep 14 '15 at 13:59
  • @PieterGoosen, Checked the pre_get_posts and everything was fine :) The problem was the missing ignore_sticky_posts parameter, though I don't think it's the right way to work. – Marin Bînzari Sep 14 '15 at 14:23
  • Jip, that also explains your issue. Sticky posts are simply added on top of the actual queried posts. :-) – Pieter Goosen Sep 14 '15 at 14:27

It were the sticky posts who ignored my posts_per_page. After setting 'ignore_sticky_posts' => true the result was correct !

| improve this answer | |
  • 1
    That is not totally true. The sticky posts doesn't make posts_per_page be ignored, what is happening is that sticky posts are always added to the top of the actual query but not into it. So it may be possible that you get more posts in the first page than the number you have set in posts_per_page argument, but it is not being ignored. That is how it is designed and how it is explained in codex. – cybmeta Sep 14 '15 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.