AnonymousInactive
haha yes. That makes total sense, and it’s working as expected now. I was testing the output at the top of the file without thinking about where the results refresh…
One more thing… I would like to wrap the label and term in markup. Is there a way to return the label and term values separately?
For instance, echo $sf_current_query->get_field_string("_sft_location");
returns “Location: Africa”, but I would like it to read <dt>Location:</dt><dd>Africa</dd>
.
Thanks!
AnonymousInactive
For clarity, this is what I used:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
foreach($sf_current_query as $key) {
echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
}
I am not entirely certain what you are doing with this, but WordPress needs to post the query to a page, which you could then use this to grab the query array:
$sf_current_query = $searchandfilter->get(7050)->current_query()->get_array();
Where you change the ID to the form ID of your form.
AnonymousInactive
ok, great help over skype Trevor – exactly what i was after and pretty much all sorted – thanks!
for anyone interested
1. use pre and print r instead of var dump to get the bits you need:
$sf_current_query = $searchandfilter->get(7050)->current_query();
echo '<pre>';
print_r($sf_current_query->get_array());
echo '</pre>';
2. I ended up with this in my page template to target the ACF meta name chosen in the S&F query – i also ended up trying to cope with the All values parts being sent if no specific options are selected (i hide all items selection in front end):
global $searchandfilter;
$sf_current_query = $searchandfilter->get(7050)->current_query()->get_array();
if ($sf_current_query['_sfm_comfort']['active_terms'][0]['name'] == ""){
echo 'no preference for comfort';
} else {
echo '$sf_current_query['_sfm_comfort']['active_terms'][0]['name'] . ' comfort';
}
AnonymousInactive
Hi Trevor, got a little further with styling so thanks for that. One thing with accessing the search data so I can display what’s been searched for – i’ve looked at
https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/
but am not getting any output. I’m using ACF meta fields for all the search criteria so maybe I need to use something differently?
?_sfm_comfort=medium&_sfm_value_judgement=bestquality&_sfm_state=wa
is the query string
i’m using this in the custom page template:
echo $sf_current_query->get_fields_html(
array(“_sfm_comfort”)
);
echo $sf_current_query->get_field_string(“_sfm_comfort”);
also doesn’t give any result.
the var dump gives:
array(3) { [“_sfm_comfort”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(6) “Medium” [“value”]=> string(6) “medium” } } } [“_sfm_value_judgement”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(12) “Best Quality” [“value”]=> string(11) “bestquality” } } } [“_sfm_state”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(2) “WA” [“value”]=> string(2) “wa” } } } }
help appreciated – cheers
Mike
You would need to do some custom coding. There are many examples in this forum. Such as this:
https://support.searchandfilter.com/forums/topic/how-can-i-display-the-selected-search-parameters-in-the-results-screen/
They all have the keyword
sf_current_query
in them.
AnonymousInactive
I have resolved the issue by inserting a To of today’s date before the ajax request is submitted and also got the current_query array to output correctly.
Am I right in thinking you don’t currently have any checks in place to ensure a To and From date are set before submitting?
The first thing then is to find what the array (data) looks like after you submit a search (with values in those two fields). Into whichever results template you are using, I need you to add this PHP code (before the loop runs), and it will print out the array of data to your screen, which you can then post back here within code ticks (the backwards quote mark that is on the key normally to the left of the main keyboard ‘1’ key, one before the code and one after it):
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(12345)->current_query()->get_array();
echo '<pre>',print_r($sf_current_query,true),'</pre>';
?>
Where I have used 12345
, you need to replace that for the ID of your form.
The first thing to do is, in the code, before you make a change, use the PHP print_r
function to output the query array to the screen, and that, after you modify it, do the same again, and compare the arrays. Like this:
echo '<pre>',print_r($sf_current_query,true),'</pre>';
I have not actually used the sf_edit_query_args function myself.
AnonymousInactive
Hi there I recently followed the example https://support.searchandfilter.com/forums/topic/null-fields-not-returning-results/ as I have an identical issue.
I used this code pretty much verbatim and a print_r shows all the range fields have been removed from $sf_current_query, HOWEVER the search still behaves as though they are still there and is returning 0 results. If I manually edit the search URL it works fine.
How do I make sf_edit_query_args actually change the search?
Thanks,
Caroline