WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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 );
add_action( 'pre_get_posts', 'wpse72961_filter_pre_get_posts' );
share|improve this answer

Your Answer


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.