Skip Navigation

[Resolved] Limit the number of categories for search filter

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 2 years ago.

Assisted by: Minesh.

Author
Posts
#2514941

My WP database has hundreds of categories. Most of the posts belong to 4 categories. For historical reasons, posts can also belong to other categories. For search filter, I only want to show these 4 categories as multi-checkboxes.

I don't see an obvious option for that. Can someone point me to the right direction?

#2515167

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset views/blocks offers the filter that can help you to control what terms you want to display with your taxonomy filter.

You can add the following code to "Custom Code" section offered by Toolset or to your theme's functions.php file;
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

For example:

add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'func_include_exclude_tags', 10, 3 );
function func_include_exclude_tags( $args, $tax, $view_id ){
  
    if ( $view_id == 99999 && $tax == 'taxonomy-slug' ){
  
        $args['include'] = array( 1, 2, 3,4 ); // Edit array of term IDs you want to allow of your 4 terms
         
    }
  
    return $args;
}

Where:
- Replace 99999 with your original view ID
- Replace 'taxonomy-slug' with your original taxonomy slug

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_frontend_search_get_terms_args