Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this to exclude a particular category from the loop. It DOES that, but it also does this: On my PAGES, it displays the posts from the categories other than this one which is excluded.

/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );

function child_do_custom_loop() {

    global $paged; // current paginated page
    global $query_args; // grab the current wp_query() args
    $args = array(
        'category__not_in' => 7, // exclude posts from this category
        'paged'            => $paged, // respect pagination
    );

    genesis_custom_loop( wp_parse_args($query_args, $args) );
}
share|improve this question
    
I made an editorial modification in the Question and added the genesis tag (is it correct?). But it would be nice if you specified that in the Q title (genesis loop). What does that genesis_custom_loop function does? Is it relevant to the Q? –  brasofilo Nov 17 '12 at 16:26

1 Answer 1

Can't really help with custom Genesis code, but the WordPress way to modify the main loop is to filter pre_get_posts.

To exclude Category ID 7 from contexts other than single post pages:

function wpse72961_filter_pre_get_posts( $query ) {
    if ( is_main_query() && ! is_singular() ) {
        $query->set( 'category__not_in', 7 );
    }
    return;
}
add_action( 'pre_get_posts', 'wpse72961_filter_pre_get_posts' );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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