質問

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' ) ) ); 
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top