Forums › Forums › Search & Filter Pro › Accessing the Search Data
- This topic has 1 reply, 2 voices, and was last updated 5 years, 2 months ago by Trevor.
-
Anonymous(Private) October 7, 2019 at 12:32 pm #222988
I want to do some custom formatting depending on the used filters… I tried this:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(69991)->current_query();
echo $sf_current_query->get_fields_html(
array(“_sfm_mk_quelle_affiliate_shop”),
$args
);… and: echo $sf_current_query->get_field_string(“_sfm_mk_quelle_affiliate_shop”);
And took the field name from my search url:
https://miriamkreativ.de/material?_sfm_mk_quelle_affiliate_shop=Creativ-DiscountBut there is nothing shown unfortunately…
I tried one more thing (displaying the searchg term):
global $searchandfilter;
$sf_current_query = $searchandfilter->get(69991)->current_query();
echo $sf_current_query->get_search_term();… and this works for me. So please can you help me with the first example, showing / getting the chosen “affiliate shop”-option?
Trevor(Private) October 7, 2019 at 3:15 pm #223002To 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.
-
AuthorPosts