You would need to be using our Shortcode Display results method (as you are), and have followed the ‘guide to customising’:
https://support.searchandfilter.com/documentation/search-filter-pro/search-results/using-a-shortcode/
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(1605)->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
}
Ah, OK, then you should be able to modify that with this snippet:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(5437)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
// output what you want to show when no filter has been used
} else {
// output what you want to show when a filter has been used
}
AnonymousInactive
Thank you very much for your help, we finally got the plugin working! There is one issue remaining: The meta data of each search result is not displayed. We try to achieve something similar to this: http://opendata.ffe.de/?s=Solar
This is our current draft: http://opendata.ffe.de/searchfilter-test/
Using a short JS script, we were able to display the button, the symbol next to the title as well as the link to the category. However, we have had some trouble accessing the metadata via PHP. We followed the approach described here (https://searchandfilter.com/documentation/accessing-search-data/) and here (https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/#post-169171), but the printed results array is empty. We already checked that our ID is correct. As described earlier, we are using Elementor Pro on our page.
global $searchandfilter;
$sf_current_query = $searchandfilter->get(362)->current_query()->get_array();
echo ‘
',print_r($sf_current_query),'
‘;
How should we approach this?
AnonymousInactive
Hello Trevor,
Thanks a lot for the hard work you guys put in this great S&F.
I have a question.
I try to get the filtered Categories shown above my filter results.
As in: Categories: (here the filtered terms).
I followed this advice: https://searchandfilter.com/documentation/accessing-search-data/
And use now this code and get it in elementor with snippets:
//Get a multiple fields values by passing an array of field names
//replace 1526
with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(6890)->current_query();
echo $sf_current_query->get_fields_html(
array(“_sft_category”, “”)
);
What I notice are two things:
1. with AJAX on, after the filter search, I need to refresh the page to get the code active/filled with the active terms
2. If Ajax is off, it is automatically updating ( I think due to reload page).
Can you help me to get this working with Ajax on?
Thanks a lot in advance!
Not from within the plugin settings, but the currently applied filter IS accessible to PHP. You would need the help of a skilled third part PHP coder, I think.
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
Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.
Please note that we are (officially) closed for weekends, Christmas Day and New Years Day and will be operating limited hours on weekdays in between. However, I will be here when I can.
Our plugin send a list of matching ID’s to the WordPress database, having worked out which posts match the criteria, the the actual final query may not be of much use. It will send a query to our cache tables though. Query Monitor plugin should show you that. To get a breakdown of the actual filters in use, this code (you need to change the ID in this code – 1234 – to that of your form) will dump the array to the screen:
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1234)->current_query()->get_array();
echo '<pre>',print_r($sf_current_query,true),'</pre>';
?>
Ah. Ok, here is what to do:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1120)->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 template code here - the if have posts bit.
}
Generally speaking, the theme (or, in this case, Elementor Pro) handles such things as page titles. Our plugin does not.
Elementor elements do not have the ability to fetch search filters from our plugin, but, using PHP, you might find a way to do this. Normally, if you intend to use Ajax to refresh the results, such PHP has to run inside the Ajax Container, but I do not think, with Elementor, you can access that part of their code, so you may need to forgo the use of Ajax (disable it) to refresh the results.
The coding is likely to be complex, but 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
You could test for filtering like this, but you need to code it for the ID number of your form (replace 2611):
global $searchandfilter;
$sf_current_query = $searchandfilter->get(2611)->current_query();
if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
// do the theme pagination
} else {
// do not do theme pagination
}
Maybe the else part is not needed in your case?
Possibly, but you will need to figure where to put this code:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(2611)->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 template code here - the if have posts bit.
}