- This topic is empty.
-
AuthorPosts
-
January 9, 2013 at 11:26 am #41874
Minnow990
MemberHi 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](http://www.rossmarineideas.com “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;
remove_all_filters(‘posts_orderby’);
$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…
January 9, 2013 at 12:38 pm #120406Chris Coyier
KeymasterIn 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’
);January 9, 2013 at 12:43 pm #120410Minnow990
MemberThat’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’ );
January 9, 2013 at 12:53 pm #120413Minnow990
MemberI 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: http://www.billerickson.net/code/wp_query-arguments/
March 7, 2014 at 11:28 am #165006alvaron
ParticipantHi There,
I’ve developed a plugin that maybe can help you on excluding catagories where you need:
http://www.wpworking.com/product/woocommerce-exclude-categories-pro/
Hope it be useful
All the best
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.