Home › Forums › Lite Version › exclude category
- This topic has 14 replies, 3 voices, and was last updated 3 years, 2 months ago by
Masonry Guy.
- AuthorPosts
Olly
GuestI am using the plugin to display some posts that have multiple categories. How can i exclude a specific category using the shortcode?
Masonry Guy
KeymasterHi Olly,
Removing post of specific category is not possible yet. We are soon going to add that in our plugin. But it is going to take some time.
Thanks
Ricardo Pedrosa
GuestHi,
Any update on this? It would be extremely useful.
Thanks!
Masonry Guy
KeymasterHi Ricardo,
It is now available in our Pro version. There we have added Custom query box where you can exclude the category from cat id.
Thanks
Anita
ParticipantHi,
I tried to exclude a category by adding a custom query, but it is not working for me. What am I doing wrong? I added this code to the custom query box:
$query->set(‘cat’,’-38′)
where 38 is the category ID. I am using Genesis with Centric Pro child theme.
Thanks for your support!
Masonry Guy
KeymasterHi Anita,
You just need to set cat=-38. Can you please try this ?
Thanks
Anita
GuestIt works! Thanks for the quick reply.
Lee Rennie
ParticipantI’m trying to do the same with a WooCommerce product category. This is my code:
product_cat=-105
However it completely stops the search from working – there are no results and all I see is the little loading square. If I remove the code all products appear in the search.
Help!
Lee Rennie
ParticipantAny news on this? I have a client website due to go live and I can’t exclude a product category for the search.
Masonry Guy
KeymasterHi Lee,
For custom post type and taxonomy (product category), you need to write complex query using the filter. Please keep this in your functions.php file and this should fix the issue.
add_filter('wmlp_query', 'my_custom_query_wmlp',10,2); function my_custom_query_wmlp($args, $shortcodeID){ if ($shortcodeID == #){ // HERE # is shortcode ID $args['tax_query'] = array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'YOUR_CATEGORY_SLUG_HERE', 'operator' => 'NOT IN' )); return $args; } }
Thanks
Lee Rennie
ParticipantThanks! This worked great. Just one more thing, when there are no results, instead of a message coming up to say that, all I get is the little square loading gif – this looks like something is happening rather than the fact there are no results. Is there a way for a message to appear when there are no results?
Lee Rennie
ParticipantI’ve just realised that the code you gave me has stopped the WP Masonry grids elsewhere on the site aren’t working anymore. All I get is the square loading icon.
When I remove the code from the functions.php file they start working again. Here’s the code I’m using:
//Remove sold category from search
add_filter(‘wmlp_query’, ‘my_custom_query_wmlp’,10,2);
function my_custom_query_wmlp($args, $shortcodeID){
if ($shortcodeID == 2){ // HERE # is shortcode ID
$args[‘tax_query’] = array(array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => ‘sold’,
‘operator’ => ‘NOT IN’
));
return $args;
}
}I need to get this site live tomorrow, so I’d appreciate your help with this asap!!
Also, I didn’t hear back from you regarding the ‘no results’ message when there are no results from the search.
Thanks
Masonry Guy
KeymasterHi Lee,
Can you please try this ?
//Remove sold category from search add_filter(‘wmlp_query’, ‘my_custom_query_wmlp’,10,2); function my_custom_query_wmlp($args, $shortcodeID){ if ($shortcodeID == 2){ // HERE # is shortcode ID $args[‘tax_query’] = array(array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => ‘sold’, ‘operator’ => ‘NOT IN’ )); } return $args; }
Regarding the no result. We don’t have that currently. We forget to add that and no client ask for that yet. We will try to add in next release.
Thanks
Lee Rennie
ParticipantThis works! Amazing, thank you.
It would be great if you could add the ‘no results’ message in the next release, as it really does look like the search is still running right now even though there aren’t any results.
Thanks
Masonry Guy
KeymasterHi Lee,
Ya i agree on that. I will start working for it soon.
Thanks
- AuthorPosts