Skip Navigation

[Résolu] Empty Search Criteria

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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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 5 réponses, a 2 voix.

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

Assisté par: Minesh.

Auteur
Publications
#1375341

I have a Views search which uses two taxonomies. The shortcodes in the View are:-

[wpv-control-post-taxonomy taxonomy="service" type="select" orderby="id" url_param="wpv-service"]
[wpv-control-post-taxonomy taxonomy="county" type="select" url_param="wpv-county"]

In order to prevent Users from performing a search without providing any criteria (or only one of the two), I've implemented this hook (which Christian helped me with originally):-

add_filter( 'wpv_filter_query', 'ts1_drop_empty_search_query_140_141', 10, 3 );
function ts1_drop_empty_search_query_140_141( $query_args, $view_settings, $view_id ) {

    $ids = array(140,141);
	
    if (in_array($view_id, $ids)){
        
        if ( 
            
            ( isset($_GET['wpv-service']) && $_GET['wpv-service'] != '0' )
            
            &&  
            
            ( isset($_GET['wpv-county']) && $_GET['wpv-county'] != '0' )
            
            ) {
                            
        } else {
            
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

This works well and I'm looking to implement a similar approach for another Search which uses a taxonomy and a Types custom field but having an issue with the hook not working and allowing a search even if the postcode field is empty. The URL on the search results page contains 'wpv-wpcf-postcode' so I'm not sure why the hook isn't working.

These are shortcodes in the View:-

[wpv-control-post-taxonomy taxonomy="service" type="select" url_param="wpv-service"]
[wpv-control-postmeta field="wpcf-postcode" type="textfield" url_param="wpv-wpcf-postcode"]

and this is the hook:-

add_filter( 'wpv_filter_query', 'ts1_drop_empty_search_query_139_2149_2158', 10, 3 );
function ts1_drop_empty_search_query_139_2149_2158( $query_args, $view_settings, $view_id ) {

    $ids = array(139,2149,2158);
	
    if (in_array($view_id, $ids)){
        
        if ( 
            
            ( isset($_GET['wpv-service']) && $_GET['wpv-service'] != '0' )
            
            &&  
            
            ( isset($_GET['wpv-wpcf-postcode']) && $_GET['wpv-wpcf-postcode'] != '0' )
            
            ) {
                
            } else {
            
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

Any ideas please?

#1375351

Minesh
Supporter

Les langues: Anglais (English )

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

Ok - I need problem URL and access details to check why its not working.

*** 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.

#1376155

Minesh
Supporter

Les langues: Anglais (English )

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

Thank you for sharing all the required details.

I checked on this page and I tried to search without adding post code and it redirected me to result page. Do you mean that you want that user should not be able to search until he add the postcode on the following page?
=> lien caché

If above is true - you need to add some custom jQuery/javascript code where you should enable/disable the search button until all input/search filters are filled.

#1376181

I'm trying to avoid using jquery/js (for various reasons). Since it's possible to target the taxonomy fields as in the search I'm already using, surely it's also possible to also target a types custom field?

#1376193

Minesh
Supporter

Les langues: Anglais (English )

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

Again - I'm on this page: lien caché

When the page is loaded the first time - I do not see any records. Do you see any records when page loaded first time?

Then, If I click on the "Find" button without adding zip code, it redirected me to the search result page.

#1376197

That page only contains the search forms, the results are on different pages.

I'm disappointed you haven't responded to my last question. After a lot of further digging, I found the solution to the issue here:-

https://toolset.com/forums/topic/how-to-use-hide-search-results-until-after-user-selects-filter-by-using-function/