Forums › Forums › Search & Filter Pro › Hide all results before a search query is made
Tagged: hide results
- This topic has 7 replies, 2 voices, and was last updated 6 years, 4 months ago by Trevor.
-
Anonymous(Private) July 4, 2018 at 12:30 pm #181943
Hi Trevor,
I hope you’ve been keeping well. I’m trying to implement your plugin on another site. This time I need to do a simple search. I’m using the custom method and with action=”filter_next_query”.
I want to hide the search results before a query is made. I followed your previous method and modified the results.php but that works only for shortcode method. Can we do the same for custom method?
Trevor(Private) July 4, 2018 at 1:08 pm #181946The Custom method relies on a theme template of some sort. Are you using a theme php template, as the logic would look something like this to do as you want:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1024)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { // the theme template PHP code here }
Change the number 1024 with your form’s ID number (from the shortcode).
This code will likely need to be used within a part the template file that actually outputs the results (around the if query … have … posts bit).
Trevor(Private) July 5, 2018 at 3:08 pm #182014You would need to be using our Shortcode Display results method, and have followed the guide to customising:
Once you have a copy of the results.php file in a
search-filter
sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):global $searchandfilter; $sf_current_query = $searchandfilter->get(1024)->current_query(); if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) { echo '<div>Nothing to see here folks!</div>'; } else { // the results.php PHP code here }
Make sure you change the ID number in that snippet to the ID number of your form.
Anonymous(Private) July 5, 2018 at 3:28 pm #182020Yes Trevor, I have copied the file. But I have no idea how to start customizing the CSS on the results page since there are no element IDs from what I could see. How can I go about coding for this? Do you have any sample code for results.php that I could start with?
-
AuthorPosts