Skip Navigation

[Resolved] Hide Taxonomy from form dropdown list via checked custom field in 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by LandruF8417 1 year, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#2595483
Screenshot 2023-04-17 at 1.29.34 PM.png

I would like to hide certain Taxonomies from search form dropdown list via a checked custom term field in Taxonomy.

I currently have the following code in View Search Filter:

<label>
[wpv-control taxonomy="attorney-practice-area" url_param="wpv-attorney-practice-area" type="select" default_label="BY PRACTICE" taxonomy_order="ASC" taxonomy_orderby="name" hide_empty="true"]
</label>

And I have a checkbox custom term field in the Practice Area taxonomy with slug "hide-from-search".

How can I hide terms that has this field checked?

#2595855

Hello,

It is possible with filter hook "wpv_filter_taxonomy_frontend_search_available_terms", see below sandbox website:
Login URL: hidden link

1) Dashboard-> Toolset-> Settings-> Custom code:
hidden link
Add one item, with below codes:

add_filter( 'wpv_filter_taxonomy_frontend_search_available_terms', 'hide_terms', 10, 3 );
 
function hide_terms( $terms, $taxonomy, $view_id ) {
    $curated_terms = array();
    foreach ( $terms as $term ) {
        if (  get_term_meta( $term->term_id, 'wpcf-hide-from-search', true ) != 1) {
            $curated_terms[] = $term;
        }
    }
    return $curated_terms;
}

2) Test it in frontend:
hidden link

It won't display the specific term "term1" in frontend

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_frontend_search_available_terms

#2595871

Worked Great! Thank you for the solution, Luo Yang!