Forums › Forums › Search & Filter Pro › Getting updated search term
- This topic has 4 replies, 2 voices, and was last updated 8 years, 11 months ago by Anonymous.
-
Anonymous(Private) January 4, 2016 at 5:07 pm #33259
Hi Ross,
I’m still having an issue with getting the (new) search term when someone starts a new search from the search results page filters. As part of the filter setup on the results page, there is a search box to ‘start a new search’ if the site visitor isn’t seeing the results they want.
However, when they search on a new phrase, the new search term is reflected in the URL and the results, but not in the text at the top of the page that says “Search Results for [search term]”.
I posted about this previously here:
https://support.searchandfilter.com/forums/topic/search-variable-s-versus-_sf_s/And I did add the suggested code to my template (search-deals.php), which to the best of my recollection was working fine then, or if not I may not have tested adequately to notice.
The odd thing is that if I refresh (reload) the page of search results, then it updates the verbiage and is correct, but if I just enter a new search term and hit enter, then the page isn’t actually being reloaded, so the verbiage doesn’t change.
SO my sequence is this: On the home page I have a S&F Pro search box (no filters, just a search box) and it’s set to display results on search-deals.php. On that template is called the results page filter, which lets visitors filter their results and that filter includes a(nother) search box to start a new search if they want to. That Filter is also set to display results on search-deals.php.
SO on search-deals.php I have the following code:
<?php $search_term = ""; //get global S&F object global $searchandfilter; $current_query = $searchandfilter->get(725)->current_query(); //(NOTE 725 is the ID of my search results page filter) //check to see if a term has been found under the regular WP variable //if not, try the S&F object if(get_search_query()!="") { $search_term = get_search_query(); } else if($current_query->get_search_term()!="") { $search_term = $current_query->get_search_term(); } ?> <header class="entry-header"> <h2 class="entry-title"><?php printf( esc_html__( 'Search Results for: %s', 'quark' ), '<span>“' . $search_term . '”</span>' ); ?></h2> </header>
The problem is with the last bit – the header that write to the page the “search results for: %s” – I’m not sure how to *replace* the original search term for the new one as ‘%s’ even though the page URL is updated fine and the results are updated and correct for the new search term.
I hope this makes sense!
As always thanks for your wonderful support! 🙂
Ross Moderator(Private) January 11, 2016 at 6:26 pm #33920Ah I think I see what you mean.
If you need that text to be updated when teh results are updated, then this text needs to be inside the results container (the are that is updated on every ajax request).
If you disable ajax I assume all is working as expected?
I see your ajax selector is
#searchresultscontainer
.The page header code
<header class="entry-header"> <h2 class="entry-title">Search Results for: <span>“cancun”</span></h2> </header>
Needs to appear somewhere inside
#searchresultscontainer
, but checking the structure of your HTML, it is appearing before.Does that make sense?
It needs to appear in the same html block as where the code displays
Found 35 Results
Alternatively, you can move that ID (
#searchresultscontainer
) on to a different element in the page markup, higher up.Thanks
-
AuthorPosts