WordPress.org

Ready to get started?Download WordPress

Forums

Omit a Category from the loop (5 posts)

  1. bhunt504
    Member
    Posted 3 years ago #

    I'm trying to keep one of my categories out of the loop and only in a category archive page that is separate. Is there anyway that I can hide this category (category 11) from the loop so it shows all posts but any that are posted in category 11? Thanks!

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    query_posts

    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters
    http://codex.wordpress.org/Function_Reference/query_posts#Usage_Note

    for instance:

    global $wp_query;
    $args = array_merge( $wp_query->query, array( 'category__not_in' => array(11) ) );
    query_posts( $args );
  3. bhunt504
    Member
    Posted 3 years ago #

    Ok, that makes sense, thanks for sharing it. I think I'm getting hung up on exactly where that need to go. I've tried putting it right before the loop starts as suggested in the third link you provided. Do you have any suggestion where it needs to go? Thanks in advance!

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    Do you have any suggestion where it needs to go?

    as you said already, before the start of the loop; before the if( have_posts() ) : while( have_posts() ) : ....... code

  5. bhunt504
    Member
    Posted 3 years ago #

    Ahhhhh, perfect! Thank you so much for your help! Just what I needed.

Topic Closed

This topic has been closed to new replies.

About this Topic