Home › Toolset Professional Support › [Resolved] Hide results until the user enter a value in the filters
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 is split from https://toolset.com/forums/topic/align-distance-filter-value-and-unit-on-the-same-line/
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: Africa/Casablanca (GMT+01:00)
Related documentation:
This topic contains 8 replies, has 3 voices.
Last updated by Jamal 3 years, 11 months ago.
Assisted by: Jamal.
Hello
Where did you place the jquery code?
How can I make the organisations to appear when user puts the filters, I would like to have the organisations View to be empty when getting on the page
hidden link
Thanks
Hello Dave,
I am not sure what would you like to implement here, please correct me if I am wrong. You want to hide results on the view until the user uses the search form, right?
This can't be done out of the box and will also need custom code. Check the solutions in these similar tickets:
- https://toolset.com/forums/topic/how-to-make-default-results-blank-for-parametric-search/#post-347797
- https://toolset.com/forums/topic/troubleshoot-wpv_filter_query-in-functions-php/
Please note that this solution will also remove the markers on the map.
If you would like to keep the markers and only remove the organizations' items in the view, I will suggest to wrap the results in a conditional block that will check the values of the SEARCH form on the URL parameters.
I hope this helps. Let me know if you have any questions.
Hello Jamal,
Yes, I would like to show no results when user enters the page, they appears when user changes search parameters,
add_filter( 'wpv_filter_query', 'default_blank_func', 10, 3 ); function default_blank_func( $query_args, $view_settings, $view_id ) { if ( $view_id == 546 && !isset($_GET['wpv_post_search'])) { // if it is view 546 and default result $query_args['post__in'] = array(0); } return $query_args; }
Where do i have to include this code to make it work
I am Piotr by the way, not David 🙂
Cheers
Hello Piotr and sorry for confusing you with another user(Dave).
Any custom code needs to be added in a separate plugin, or in the theme's functions.php file, or in Toolset->Settings->Custom Code(tab) and activated.
https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
Please note that this code will not work out of the box on your website, it will need to be adapted to your use case:
- View_id=24903
- You can't rely on $_GET['wpv_post_search'] because you are not using a text search. You will need to rely on the category parameter or distance search parameter.
At the same time, the code needs to handle AJAX requests. I can help with the required code, but I can't work directly on your website without having FTP access. I prefer to work on a copy of the site locally until I get the custom code then we can implement it on the live site. Your next reply will be private to let you share FTP credentials safely.
Unfortunately, the credentials did not work for me, I only tried with the FTP protocol.
Should I try with SFTP protocol or let you check the credentials from your end. Your next reply will be private to let you share credentials safely.
Hi Piotr,
Jamal is not available at the moment so let me step in here.
The FTP access details you shared is not working at this end. If you can send me wp-admin access details then I will try to add the code to "Custom Code" section offered by Toolset where we can put such custom code then FTP access details will not be required.
But can you please send me working wp-admin as well as FTP access details and I will try to put the code that Jamal shared.
*** 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.
Hello Piotr,
Thank you for the FTP access, I confirm it works for me.
So, I added the following code to Toolset->Settings->Custom code and it does empty the results if no filter is entered, either the category or the distance filter.
add_filter( 'wpv_filter_query', 'empty_view_results_if_no_filters',99,3 ); function empty_view_results_if_no_filters( $query_args, $views_settings, $view_id) { global $WP_Views; // comma-separated list of view IDs where you want to apply this filter $view_ids = array( 24903 ); // if in the right view if (in_array($view_id, $view_ids)){ // Check if there is a category filter $category = isset( $_GET['wpv-category-of-organisation'] ) ? $_GET['wpv-category-of-organisation'] : false; // Check if there is a distance filter, both the center and the radius $distance = ( isset( $_GET['toolset_maps_distance_radius'] ) && isset( $_GET['toolset_maps_distance_center'] ) ) ? ( isset( $_GET['toolset_maps_distance_radius'] ) && isset( $_GET['toolset_maps_distance_center'] ) ) : false; if ( !$category && !$distance ) { // empty the results $query_args['post__in'] = array(0); } } return $query_args; }
I'll let you test from your side. If you encounter any issues with it, please provide the steps to follow to reproduce the same issues.
Hey Jamal
I tested it and it work fine apart the fact that the map shows the default location, is it possible to show map of Scotland on the default?
Is it possible to show the results only when pressing "Submit" or "USE MY LOCATION" button, at the moment it refreshes when choosing the support from dropdown or when changing the distance value
However, the page does not look good on the safari browser (see screenshot)
Many thanks
Piotr
New threads created by Jamal and linked to this one are listed below:
https://toolset.com/forums/topic/default-map-center-when-there-are-no-results/
It seems that this will need some custom code to be implemented. Let me check with our 2nd Tier about it and get back to you.
However, for support rules, we are able to handle only one issue at a time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason, I have created a new ticket to handle this map center feature so it can easily be found by other users.