Skip Navigation

[Resolved] Filtering by taxonomy when taxonomy is hierarchical

This support ticket is created 7 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by johnM-19 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#508721

In a nested View, with a post inner and taxonomy outer, set the inner View’s Query Filter to “Set by the parent Taxonomy View.”

If the taxonomy is hierarchical, the filter passes not just the items matching a taxonomical category, but those matching the category’s children as well.

So a post can get shown multiple times, once for its category, once for the category’s parent, once for the category’s grandparent, etc.

This seems like a bug to me, but either way, is there a way to filter only posts that match the categorical term, not those that match the term’s children also?

#508825

Dear John,

There isn't such a built-in feature within Views plugin, but you can try with the Views filter hook "wpv_filter_tax_filter_include_children", for example, add below codes into your theme/functions.php:

add_filter('wpv_filter_tax_filter_include_children', 'no_child_term_func', 10, 3);
function no_child_term_func($include_child, $category_name, $view_id){
	if($view_id == 123 && $category_name == 'my-tax-slug'){
		$include_child = false;
	}
	return $include_child;
}

Please replace 123 with the child view's ID, replace "my-tax-slug" with the custom taxonomy slug.

#508947

That worked. Thanks!

It would be nice if this were a standard option.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.