Skip Navigation

[Resolved] Alter Fliter

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

This topic contains 2 replies, has 2 voices.

Last updated by Pete 2 years, 8 months ago.

Author
Posts
#2132853

Hi there,

Shane at support kindly helped me out with the code below, this so only certain taxonomies display in a drop down.
Is there a way to do the opposite, by that I mean if we add just one or two taxonomies they will 'not' display in drop down?

The reason, we have a location taxonomies and this has about 30, we wish to exclude 2 in the drop down.
As we often add to this, it would be far easiest to add the two we didn't wish to display.

Worth an ask 🙂

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 == 37131 && $taxonomy == 'property-feature'){

$args['slug'] = array(

'romantic-bolthole',
'fun-family-holiday',
'coastal-village',
'contemporary-interior',
'luxurious-property',
'open-fire',
'hot-tub',
'close-to-coast',
'close-to-shops-pubs',
'close-to-restaurant',
);
}
return $args;

}

#2133433

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Instead of populating the $args with an array of slugs you want to include, you can instead provide an array of terms to exclude, but the exclude argument requires term IDs rather than term slugs, so you'll need to look those up. (If you go to the list of terms you can see the IDs when hovering over the edit links.)

So your code would then look something like this:

add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'ts_mod_tax_filter', 10, 3 );
function ts_mod_tax_filter( $args, $tax, $view_id ){

    if ( $view_id == '37131' && $tax = 'property-feature' ){

        $args['exclude'] = array( 1, 2, 3 ); // Edit array of term IDs to exclude
    }

    return $args;
}
#2133483

Thank you Nigel, worked just great.

Regards, Pete

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