Sauter la navigation

[Résolu] Exclude Specific Pages From Search

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to filter taxonomy filter dropdown options and display specific terms

Solution:
There is no way to filter the term options added to taxonomy filter select box using views but a workaround would be:
You need to use WordPress standard hook "pre_get_terms" in order to filter the taxonomy query.

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/exclude-specific-pages-from-search/page/2/#post-1611953

Relevant Documentation:

This support ticket is created Il y a 5 années. 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)

Ce sujet contient 17 réponses, a 2 voix.

Dernière mise à jour par Pete Il y a 5 années.

Assisté par: Minesh.

Auteur
Publications
#1610745
pl z see.jpg

Hi Minesh,

The ones that need removing from the drop down are in the squared off areas.

#1611953

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Can you please check now: lien caché

I've added the following term custom field group where I've added the checkbox field and assigned this group to display with the area taxonomy:
=> lien caché

Then, I've set the checkbox field for the terms Lake District, Norfolk and Suffolk.
=> lien caché

To display only terms where the checkbox is set with the home page view, I've added the following code to the "Custom Code" section offered by Toolset:
=> lien caché

function func_specific_terms_viewfilter( $query ){
    global $post;
     
    if ( $post->ID == 12 && $query->query_vars['taxonomy'][0] == 'area' && !is_admin() ) {
         
        $meta_query_args = array(
                'relation' => 'AND', // Optional, defaults to "AND"
                                array(
                                'key'     => 'wpcf-display-on-home',
                                'value'   => '1',
                                'compare' => '='
                                )
                            );
    $meta_query = new WP_Meta_Query( $meta_query_args );
    $query->meta_query = $meta_query;
         
    }
}
add_action( 'pre_get_terms', 'func_specific_terms_viewfilter',101,1);

Now, on homepage I can see only terms with the "Destination" dropdown where we set the checkbox:
=> lien caché

#1612191

My issue is resolved now. Thank you!