Skip Navigation

[Resolved] How to show only a few tags in Filters in the Search feature?

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

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 10 replies, has 2 voices.

Last updated by Minesh 2 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2150241

Tell us what you are trying to do?

I want to show only a few tags in Filters in the Search feature. I also need this to be in Checkboxes because I want the user to be able to select multiple tags.

Please let me know if you need me to clarify.

Thanks!

Any help would be greatly appreciated.

#2150399

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share bit more information about what tags you want to display with what search filter?

Are you talking about view's custom search filter?

Once you share all required information I will review it and get back to you.

#2150507

Hey Minesh,

I'm not 100% sure if its the View's custom search filter. Here is a screenshot of the search filter I'm referring to: hidden link

I have over 100 tags in my posts (hidden link) but I only want to show a few tags for our users to use to filter the results.

#2150511

Minesh
Supporter

Languages: English (English )

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

Yes - the post_tags is added as view's custom search filter.

You can use the View's filter "wpv_filter_taxonomy_frontend_search_get_terms_args" to limit the terms as per your requirement that is presented as view's custom search filter.
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_frontend_search_get_terms_args

You can see the example given with the above URL and reduce the terms as per your requirement.

#2150955

Thanks for this.

Would you be able to provide an example for my use case?

View ID = 552580
Taxonomy slug = post_tag
Tags I want to filter = biology, psychology

Here's what I've tried:

add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'prefix_modify_get_terms_args', 10, 3 );
 
function prefix_modify_get_terms_args( $args, $taxonomy, $view_id ) {
    $args['slug'] = array(
        'biology',
        'psychology',
    );
  	$taxonomy => 'post_tag';
  	$view_id => '552580';
    return $args;
}

Can I also add this into the JS editor of Views or do I need to add it to functions.php?

#2151195

Minesh
Supporter

Languages: English (English )

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

Here is the sample code you should try to use:

add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'prefix_modify_get_terms_args', 10, 3 );
 function prefix_modify_get_terms_args( $args, $taxonomy, $view_id ) {
  
if ( $view_id == 552580&& $taxonomy == "post_tag") {
          $args['slug'] = array(
        'biology',
        'psychology',
    );
}

  return $args;
}
#2152365

Hey Minesh,

Thanks for the sample code. I tried it but it still shows all the tags.
Screenshot of Views: hidden link
Screenshot of results page showing all tags: hidden link

I also confirmed that the view ID is correct (552580).

#2152377

Minesh
Supporter

Languages: English (English )

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

Please share problem URL and access details so I can check whats going wrong with your setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2152407

Minesh
Supporter

Languages: English (English )

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

First of all - After checking to debug the information you shared with us, I found that you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

Can you please first update ALL plugins to latest version.

#2152411

I see. Thanks for checking this out. I`ll let you know when I update and hopefully it works.

#2152527

Minesh
Supporter

Languages: English (English )

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

Ok fine - thanks, let me know how it goes and also if it does not work let me know where exactly you added the code.

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