Tell us what you are trying to do?
We have a custom hierarchical taxonomy for destinations. I have created an Elementor template for destination archives.
We have these custom post types which use the destinations taxonomy.
* Properties
* Excursions
On each destination archive "page", we have a section each for Properties and Excursions.
* For the Properties section, we want to only show Properties (not Excursions) for the current Destination (including child destinations), as well as have name search, plus filters for rating, destination (self and child destinations only) and collection (another taxonomy that is flat).
* For the Excursions section, we want to only show Excursions (not Properties) for the current Destination (including child destinations), as well as have name search, plus a filter for destination (self and child destinations only).
Please see the screenshot for clarity or go to hidden link
We are limited to WordPress.com at this time, thus I am using the Snippets plugin to add PHP functions. I am currently trying to limit the search results to the current destination + children.
Limit Property Search Results to Current Term:
add_filter( 'wpv_filter_query', 'filter_include_cat_fn', 1000 , 3 );
function filter_include_cat_fn( $query_args, $view_settings ) {
// check if specific view
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 14020) ) {
// set the parent tax term filter if no tax filter is set
if(empty($query_args['tax_query']))
{
$query_args['tax_query'][0]['taxonomy'] = 'destinations';
$query_args['tax_query'][0]['field'] = 'id';
$query_args['tax_query'][0]['terms'][0] = get_queried_object_id();
$query_args['tax_query'][0]['operator'] = 'IN';
$query_args['tax_query'][0]['include_children'] = true;
$query_args['tax_query']['relation'] = 'AND';
}
}
return $query_args;
}
This works however the search/filters/reset are broken.
Limit Excursion Search Results to Current Term:
add_filter( 'wpv_filter_query', 'filter_include_cat_fn2', 1001 , 3 );
function filter_include_cat_fn2( $query_args, $view_settings ) {
// check if specific view
if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 14035) ) {
// set the parent tax term filter if no tax filter is set
if(empty($query_args['tax_query']))
{
$query_args['tax_query'][0]['taxonomy'] = 'destinations';
$query_args['tax_query'][0]['field'] = 'id';
$query_args['tax_query'][0]['terms'][0] = get_queried_object_id();
$query_args['tax_query'][0]['operator'] = 'IN';
$query_args['tax_query'][0]['include_children'] = true;
$query_args['tax_query']['relation'] = 'AND';
}
}
return $query_args;
}
Similar to above, the search/filters/reset are broken, except the destination filter.
Is there any documentation that you are following?
https://toolset.com/forums/topic/create-a-view-to-limit-results-to-a-parent-taxonomy-then-filter-by-child/
Is there a similar example that we can see?
Sorry, I do not have a functioning example yet.
What is the link to your site?
hidden link