The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other WordPress Exclude Category (not working?)

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #41874

    Hi all,

    I have a problem with trying to exclude a category from a WordPress site. It has woocommerce installed and I’m using the WooThemes theme “Shelflife”. It’s a ecommerce site ([]( “Ross Marine Ideas”)) and I want to exclude a category with plain drinkware from showing up in the more products section of the home page. The category ID is 234 and I’ve tried EVERYTHING I can think of to exclude it — googled how and I’ve put it in the array as _’cat’ => ‘-234’_ and as a separate WP_query(); function….

    Could use a little help. Also sent Chris an email asking for some help.

    What am I doing wrong!?

    $i = 0;
    $args = array( ‘orderby’ => ‘rand’, ‘post_type’ => ‘product’, ‘posts_per_page’ => $settings );

    $args = array();

    // Exclude the featured products based on the theme option setting.
    if ( $settings == ‘true’ ) {
    $args[] = array( ‘key’ => ‘_featured’, ‘value’ => ‘no’, ‘compare’ => ‘=’ );

    $args[] = array( ‘key’ => ‘_visibility’, ‘value’ => array( ‘visible’, ‘catalog’ ), ‘compare’ => ‘IN’ );

    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); $_product = &new WC_Product( $loop->post->ID ); ?>

    //Some HTML code and other loop code down here…

    Chris Coyier

    In the code you’ve posed here, you haven’t included any category removal. It needs to be in the arguments you pass WP_Query.

    $args = array(
    ‘orderby’ => ‘rand’,
    ‘post_type’ => ‘product’,
    ‘posts_per_page’ => $settings,
    ‘cat’ => ‘-234’


    That’s because what I posted was the original code. I’ve tried adding in the exclusion for the category, but the result is the same. It’s like wordpress is ignoring the argument for excluding the category. I updated my code and if you look at the site now, you’ll still find items in the “more products” section that are plain. (Refresh a few times and you’ll eventually find the word “plain” in at least one of the products)

    This is my code for that part now:

    $args = array( ‘orderby’ => ‘rand’, ‘post_type’ => ‘product’, ‘posts_per_page’ => $settings, ‘cat’ => ‘-234’ );


    I also tried this earlier today:

    $loop = new WP_Query( $args.’&cat=-234′ );

    but there was no luck there either. I tried using tag_id as well, and I’ve been looking at all the arguments here to find an alternative, but to no avail:


    Hi There,

    I’ve developed a plugin that maybe can help you on excluding catagories where you need:

    Hope it be useful

    All the best

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Other’ is closed to new topics and replies.