0

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) );
}
1
  • 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, 2012 at 16:26

1 Answer 1

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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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