[Résolu] If a user choose a category or anything in the search form, it not shows correct
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.
Okay, yes, I agree about those 5 seconds and ongoing showing.
Second, yes, I need a solution, where we have in a first stage no result showing. And once the user is either choose something from the drop downs or use the text search, it will showing results according.
If You can help me with this wpv_filter_query API filter, would be great, I am not 100% familiar how to do that.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+01:00)
You can add this code to your site (at Toolset > Settings > Custom Codes), you should just need to edit the ID of the View:
/**
* No initial results
*
* Don't show View results until a filter has been applied
*
* Tests for custom field filters, taxonomy filters, or text searches
*/
function tssupp_no_initial_results( $query_results, $view_settings, $view_id ){
$target_views = array( 226 ); // Edit to add IDs of Views to add this to
if ( in_array( $view_id, $target_views ) ) {
// if there is a search term set
if ( !isset( $query_results->query['meta_query'] ) && !isset( $query_results->query['tax_query'] ) && !isset( $query_results->query['s'] ) ) {
$query_results->posts = array();
$query_results->post_count = 0;
$query_results->found_posts = 0;
}
}
return $query_results;
}
add_filter( 'wpv_filter_query_post_process', 'tssupp_no_initial_results', 10, 3 );
You will need to delete the text for "No items found" from the View.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+01:00)
I suspect when you added the code in the Toolset settings you didn't activate the code snippet?
There is little practical difference between adding the code in Toolset settings vs. editing your theme's functions.php file, except it is supposed to be more convenient ( 🙂 ) and means the code isn't lost if you change theme.
But the important thing is whether the code works, and it sounds like it does, yes?
Sorry it took a while to get to the solution, the other method should be simpler, but it can't work very easily with your View that has automatic pagination.