Tell us what you are trying to do?
I want to start my toolset view being filtered under one of it's taxonomies. So when entering the View page, the library is already filtered showing results for "taxonomy 1". Is this a possibility?
Mateus Getulio
Supporter
Languages:
English (English )
Timezone:
America/Sao_Paulo (GMT-03:00)
Hey there,
Thank you for contacting our support.
Views are based on the underlying WordPress WP_Query class, and you can add additional query arguments via the wpv_filter_query filter (see https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query ).
Please check a snippet that would allow you to filter your view results based on a taxonomy slug and/or name:
add_filter( 'wpv_filter_query', 'filter_taxonomy_1',99,3 );
function filter_taxonomy_1( $query_args,$views_settings, $view_id) {
if ($view_id == 123){
$query_args = array(
'post_type' => 'page',
'tax_query' => array(
array(
'taxonomy' => 'taxonomy_1',
'field' => 'name',
'terms' => 'featured',
'operator' => 'IN'
),
),
);
}
return $query_args;
}
You need to replace the view ID, the post type and taxonomy name.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
I hope this helps and here are some useful guides on the topic:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/
For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
Kind regards,
Mateus