Skip Navigation

[Resolved] Start toolset view with specific taxonomy

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 1 reply, has 2 voices.

Last updated by Mateus Getulio 1 year, 5 months ago.

Assisted by: Mateus Getulio.

Author
Posts
#2646215

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?

#2646597

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