To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots 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
Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.
You could temporarily use this code in your results template to display the full filter array so that you can work out the exact array part that holds the data you want:
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
echo '<pre>',print_r($sf_current_query,true),'</pre>';
?>
Where the ID needs to match that of your form.
AnonymousInactive
I have a need to refresh the custom results page using an html form that controls how results are displayed, (map VS list). When the page gets called by itself, (form action = call this page), setting the WP_query $args, (in my case… $args = array(‘search_filter_id’ => 1576,’post_type’ => ‘post’,’paged’ => $paged); ), doesn’t work since the value for ‘search_filter_id’ => 1576 is NULL when the page gets refreshed. I’ve tried a few ways to contruct a new $args value that I set in a $_SESSION variable but can’t get it to work. Here’s what I’ve tried:
Executed on initial page display—Works
1. $sf_current_query = $searchandfilter->get(1576)->current_query();
2. $original_sf_query_args =array($sf_current_query->get_array());
3. $passed_args_array = array($original_sf_query_args,’post_type’ => ‘post’,’paged’ => $paged);
4. $_SESSION[‘passed_args_array’] = $passed_args_array;
5. $args = array(‘search_filter_id’ => 1576,’post_type’ => ‘post’,’paged’ => $paged);
6. $query = new WP_Query($args);
Executed on subsequent page displays—Doesn’t Work
1. $args = $_SESSION[‘passed_args_array’];
2. $query = new WP_Query($args);
What might I be doing wrong?
The currently applied filters are accessible to PHP. You would need the help of a skilled third party PHP coder, I think, to modify the template code for the results loop.
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.
The currently applied filters are accessible to PHP. You would need the help of a skilled third party 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.
Does it appear if you edit the template and add this code:
$sf_current_query = $searchandfilter->get(334)->current_query();
echo '<pre>';
print_r($sf_current_query->get_array());
echo '</pre>';
(this will print an array to the page)
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?
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>';
?>
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
To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots 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
Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.
You could temporarily use this code in your results template to display the full filter array so that you can work out the exact array part that holds the data you want:
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
echo '<pre>',print_r($sf_current_query,true),'</pre>';
?>
Where the ID needs to match that of your form.