Yes, that is totally possible. You need to edit the results.php template file you are using, like this:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(36613)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
echo '<div>Nothing to see here folks!</div>';
} else {
// your current results.php code here
}
Hi
There is a code back tick on most keyboards; use that once before and once after the code you post. On my keyboard it is the key to the left of the 1 key.
As to fetching the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lost of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
… and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/
AnonymousInactive
Hi! Still loving this plugin. It quickly became a favorite. Quick question: I have results.php with the following else:
`
else
{
?>
<div class=’search-filter-results-list’ data-search-filter-action=’infinite-scroll-end’>
<h3>We couldn’t find anyone with “<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(4716)->current_query();
echo $sf_current_query->get_search_term();
?>”.</h3>
</div>
<?php
}
`
My problem though is that when I sort by a taxonomy, eg orgs or divisions with a drop down cromobox without a search term the "". is left blank. What do I need to add to the above to return the taxonomy/taxonomies?
Thanks!
You are not using our integration guide for Elementor?
https://searchandfilter.com/documentation/3rd-party/elementor/
The https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lost of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
… and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/
Note that (as far as I know) you cannot run PHP in Elementor elements. It has to be inside a PHP template, or inside a shortcode that can run PHP (there are such plugins out there that let you make shortocdes that use PHP).
AnonymousInactive
Hello,
I have s&f pro on elementor and I like to show the tags/cats of the filtered results.
I found this page: https://searchandfilter.com/documentation/accessing-search-data/
But the PHP string is not working on my page, I just see a part of the string where I would like to have the meta of the filtered posts.
Used this code and put it in a text and html field, both same results:
<?php
//grab the active query from our search form
//replace 1526 with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(REPLACED WITH S&F ID)->current_query();
?>
AnonymousInactive
I’m using Search and Filter Pro. I’ve created a form and implemented it into my theme using <?php echo do_shortcode( ‘[searchandfilter id=”239″]’ ); ?>
The search, category, and tag filters are working well with AJAX enabled. I’ve also added a date range filter – when I choose a start date, and end date range there is a pause as the AJAX refreshes the results, but nothing changes. I have the setting for Make searches bookmarkable enabled, and this works with the other filters I have, but nothing happens with the date range.
I have a default div of content showing when the nothing has been filtered
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==””)) {
/* Default div here */
}
When I do a date range search the default div never goes away – it is as if nothing is being detected when a start and end date is entered.
Help please.
AnonymousInactive
Well I might have asked wrong way 🙂
The thing is the filter as I call it with the shortcode shows up, but if I try to filter results (e.g. I select one region in the dropdown or white a text to the search input and press submit), nothing changes – the result set of $trainers remains unchanged (unfiltered), so as the $GLOBALS[‘wp_query’]->request).
From your first link you provided, I tried this code:
$sf_current_query = $searchandfilter->get(1513)->current_query();
echo '<pre>';
print_r($sf_current_query->get_array());
echo '</pre>';
and got
array (size=10)
'paged' => int 1
'search_filter_id' => int 1513
'search_filter_override' => boolean false
'posts_per_page' => int 10
'post_status' =>
array (size=1)
0 => string 'publish' (length=7)
'meta_query' =>
array (size=0)
empty
'post_type' => string 'trainer' (length=7)
'is_search' => boolean true
'is_archive' => boolean true
'post__in' =>
array (size=7)
0 => int 1284
1 => int 1495
2 => int 1503
3 => int 1504
4 => int 1505
5 => int 1506
6 => int 1508
(notice there is no sign of filtering in the array). This is my main problem.
Ah, I see. I misunderstood your initial question. I am sorry for that. At least, I think I understand.
Showing the word searched for is not so difficult. If you have other filters, then it becomes a little more complex, but I can give you links. The documentation page:
https://searchandfilter.com/documentation/accessing-search-data/
This thread might help you:
https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/
… and this search will give similar threads I think:
https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/
Ah, you would need to code it in your PHP template then, much like this:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1033)->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 here
}