Forums › Forums › Search & Filter Pro › Customizing what displays before any search has been performed
- This topic has 6 replies, 2 voices, and was last updated 6 years, 7 months ago by Trevor.
-
Anonymous(Private) May 6, 2018 at 7:06 pm #176020
I have a form with Relevanssi active, displaying results using a shortcode, with a custom results.php template in my theme. It all works great, except that the initial view of the page shows the “No results found…” text from the “else” part of my
if ( $query->have_posts() )
code.That’s not a great place to start for people coming to the search page who have not searched for anything yet. I would love to be able to customize my results in this case better.
1. Is there any way, in a newly arrived or reset results page, where there are no
?_sf_s=asdf
style parameters in the url at all, I can instead show all possible results? Like an unfiltered listing of the post types included in the search form.2. If that’s not possible, can I least customize the returned text to be different than if no results are found? Something equivalent to
elseif (~nothing-searched-yet no-parameters-in-URL~) { echo "Let's get started!"; } else { echo "No result found."; }
Does that make sense? Thanks for your help!
Trevor(Private) May 7, 2018 at 11:22 am #176099It does indeed make sense. Here is how you would code what you want to do:
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 { // your template archive code/loop OR results.php code here }
Change 1024 to the ID number of your form (from the form shortcode).
Anonymous(Private) May 7, 2018 at 6:14 pm #176170Thank you, Trevor! This code works well to show different text on a “blank” form.
Did you have any thoughts about the first half of my question? Is there a way for the S&F Pro results to include all items to start, rather than none? Right now my form is functioning in an un-intuitive way — in addition to showing nothing at the start, it also shows nothing for any combination of items unless a search term or a taxonomy has been chosen. For instance, if you leave the search field blank and have “All topics” chosen, and choose an author from the dropdown, it says no results (even though there are posts by that author). Or if I choose a post type, and leave it on “All authors,” and click submit, I still get no results.
Is this something particular to my site, or is it the way the plugin functionality is supposed to work? Fundamentally, I would like if the results defaulted to show every possible result, so if I chose an author and clicked “submit” I got all posts by that author that meet the other criteria of the form.
-
AuthorPosts