Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I successfully use pre_get_posts to exclude two categories from the main loop on the homepage, archive and author page. My problem is that I want to display those categories in the sidebar! Here is the code (functions.php):

function exclude_category_home($query) {
if ($query->is_home && $query->is_main_query() || $query->is_archive || $query->is_author) {
    $query->set('cat', '-3,-41'); 
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category_home');

That doesn't work. Why?

SOLVED:

function manipulation_parse_request() {
    add_action('pre_get_posts', 'manipulation_pre_get_posts');
}
add_action('parse_request', 'manipulation_parse_request');

function manipulation_pre_get_posts($wp_query){
    if ($wp_query->is_home || $query->is_archive || $query->is_author) {
        $wp_query->set('cat', '-3,-41');                
    }
    return $wp_query;
} 
share|improve this question
3  
If the above solution beneath SOLVED works, please add that as an answer to your question then accept your own answer as correct. – userabuser Oct 12 '12 at 2:12

closed as too localized by Rarst Oct 13 '12 at 22:16

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.