Skip Navigation

[Resolved] Exclude a taxonomy from a search

This support ticket is created 6 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by leilaG 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1116485
exclude-taxonomy.PNG

Hi, how do we exclude a specific taxonomy from showing in a filter/search?

#1116994

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Leila

Well the simplest solution would be to inspect the page source and then add a CSS rule to hide the term checkbox in question.

To avoid the checkbox being added to the page in the first place you would need to add some custom code (https://toolset.com/documentation/adding-custom-code/).

We don't have a Toolset API hook covering this, but you can use the standard WP get_terms filter, checking that you are on the right page (i.e. you'll need the ID of the page—or pages—where this View is inserted), and you'll also need the slugs of the terms you want to exclude.

<?php
/**
 * Filter terms available in a Views taxonomy filter
 */
function tssupp_get_terms( $terms, $taxonomies, $args, $tax_query ){

	global $post;
	if ( in_array( $post->ID, array( 113 ) ) ) { // Edit page ID

		$exclude = array( 'active', 'complete' ); // Slugs of terms to exclude

		foreach ($terms as $key => $term) {

			if ( in_array( $term->slug, $exclude ) ) {

				unset( $terms[$key] );

			}
		}
	}	

	return $terms;
}
add_filter( 'get_terms', 'tssupp_get_terms', 10, 4 );
#1118224

My issue is resolved now. Thank you!