My search does not work anymore, the same goes for my categories. It now shows literally all the posts until the page limit is reached, instead of the specified ones. This happened after I made sure that the sticky posts I show on top of my page are not repeated in the main loop.

I added this to my functions.php

add_action('pre_get_posts', 'theme_ignore_sticky');
function theme_ignore_sticky($query)
    if (is_home() && $query->is_main_query())
        $query->set('ignore_sticky_posts', true);

and put this before my main loop in in the index.php

query_posts( array( 'post__not_in' => get_option( 'sticky_posts' ), 'paged' => get_query_var( 'paged' ) ) ); 
  • Possibly unrelated, but I highly recommend using get_posts instead of query_posts. Check this question for reasons. Dec 18 '16 at 16:57

I see two issues in your code.

First, you pass what could be a string into post__not_in, which accepts an array of posts IDs (that's fine if your option holds an array of IDs, but always good to verify).

Second, you seem to be repeating the same thing twice: you modify the query with pre_get_posts hook, and then you do it again by passing something into query_posts. In the documentation (this page, the posts_per_page part), they demonstrate the two techniques as alternatives of doing the same thing.

  • Many thanks for your answer, I have figured it out now. Dec 18 '16 at 20:29

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.