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 (rossmarineideas.com) 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!?
<?php
$i = 0;
remove_all_filters('posts_orderby');
$args = array( 'orderby' => 'rand', 'post_type' => 'product', 'posts_per_page' => $settings['product_limit'] );
$args['meta_query'] = array();
// Exclude the featured products based on the theme option setting.
if ( $settings['featured_exclude'] == 'true' ) {
$args['meta_query'][] = array( 'key' => '_featured', 'value' => 'no', 'compare' => '=' );
}
$args['meta_query'][] = 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...
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)
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 (rossmarineideas.com) 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!?
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.
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:
I also tried this earlier today:
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: http://www.billerickson.net/code/wp_query-arguments/