Skip Navigation

[Resolved] Exclude a Category from Taxonomy Views

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a taxonomy View and I would like to exclude one category.

Solution: You can accomplish it with custom code and the wpv_filter_taxonomy_query API:

//Exclude specific term from term View
add_filter( 'wpv_filter_taxonomy_query', 'ts_modify_tax_query', 10, 3 );
 
function ts_modify_tax_query( $tax_query_settings, $view_settings, $view_id)
{
  $views = array( 12345 );
 
  if( in_array( $view_id, $views ) ) {
    $tax_query_settings['exclude'] = '67890';
  }
  return $tax_query_settings;
}

Replace 12345 with a comma-separated list of View IDs where you would like to exclude a specific term. Then replace 67890 with a comma-separated list of term IDs you would like to exclude. Place this code in a child theme's functions.php file, or in a new custom code snippet in Toolset > Settings > Custom Code.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by dorM 5 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1275125

I am trying to: Exclude 1 Category from Woocommerce Product Categories in Taxonomy Views

Link to a page where the issue can be seen: hidden link

I expected to see: how i can exclude a category

Instead, I got: i can only choose which one to display, and not to not display.

#1275155
Screen Shot 2019-06-23 at 9.55.44 AM.png

In the Query Filter panel, you can choose the option "No one of the following" as seen in this screenshot. That should allow you to choose one product category to exclude. If you cannot see the Query Filter panel, scroll to the top right and click "Screen Options". You can enable the Query Filter panel here.

#1275169

Hi,
Thank you.
The Filter "No one of the following" is shown only when the View is displaying a certain CPT. in my case i'm displaying Taxonomies -> Wooommerce Categories.
appreciate your help.

#1275179

I see, there's no way to do this from the Views editor page. You can accomplish it with custom code and the wpv_filter_taxonomy_query API:

//Exclude specific term from term View
add_filter( 'wpv_filter_taxonomy_query', 'ts_modify_tax_query', 10, 3 );

function ts_modify_tax_query( $tax_query_settings, $view_settings, $view_id)
{
  $views = array( 12345 );

  if( in_array( $view_id, $views ) ) {
    $tax_query_settings['exclude'] = '67890';
  }
  return $tax_query_settings;
}

Replace 12345 with a comma-separated list of View IDs where you would like to exclude a specific term. Then replace 67890 with a comma-separated list of term IDs you would like to exclude. Place this code in a child theme's functions.php file, or in a new custom code snippet in Toolset > Settings > Custom Code.

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

#1275187

My issue is resolved now. Thank you!