At the moment i am building a website where people can filter posts. Once filtered it is the intention that it should be possible for people to leave their emailadress. Once they do that i save the “$sf_current_query->get_search_term()” and “$sf_current_query->get_array()” to the database to make it possible to repeat the query.
Would it be possible to use the saved data to query the results later on? if so with which function? I already tried “set_field_values_array()” but i cannot get it to work.
The results do not need to be filtered, i just want to check if there are any results afterwords with WP_Query.
Hope that you can help me with the above, thanks in advance!
When I do a var_dump, it shows the info that is expected (hidden for now) — so the id and everything seems to be correct.
However, when I try to display any of the field values, nothing shows up.
No errors in console message or anything either.
I am trying to get it to say “Search Results 10″, Air Flat/Free, Top Plate”
If you are using Ajax, you need these filter labels inside the Ajax Container. If you want them to be shown elsewhere on the page, you still have them, but hidden with CSS, inside that Ajax Container, but use jQuery to copy and paste them to where they will show after our sf:ajaxfinish event has triggered.
You will also need to be using a PHP template for the page. It will be much harder (or not possible at all) if you are using a page builder or post grid plugin/widget.
It will require some coding for which I can point you in the direction of snippets, but I cannot help you write the code, sorry, as this is not within the scope of our support.
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:
Hi Trevor,
Thank you for the response. The code you sent works well, however, it needs to be in the archive page itself to work, which is something I’m trying to avoid because that would mean the page has to reload to display the active filters.
I tried to run it through AJAX once the form submits. But I’m not getting any results. (below is the function I added to functions.php) (the ajax request works fine, so the issue is with $searchandfilter).
Is there any way to use the “$searchandfilter” class and the “current_query()” method from OUTSIDE the archive page?
I found this class that allows to output the current filters
<?php
//Get an array of objects containing data for the current search/filter
//replace <code>1526</code> with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1526)->current_query();
var_dump($sf_current_query->get_array());
?>
But what I’m really looking for is to dynamically display the filter terms AND search term on Submit (AJAX enabled). Also the ability to Clear those Filters / Search items one by one (X them out).
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:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(9490)->current_query()->get_array();
echo $sf_current_query['_sfm_UnitLocation']['active_terms'][0]['name'];
Look carefully, as only the ‘global’ line is the same.
Note, if you are using Ajax on the page, you may need to make sure that the page title is inside the Ajax Container, otherwise it will not refresh and change.
I have some questions regarding the usage and hope you can help me.
1. A drop down filter with custom ACF field. I have a front-end form created with ACF where one of the fields is Price. I have created a main filter where i use the range field with two values minimum price and maximum price and it works great. Now i am looking to create another small drop down filter with two options: Sort posts by lowest price and Sort posts by highest price. Sorry if it is obvious, but i could not find how can i achieve it using one single ACF field.
2. The reset button does not work when filter is not submitted with AJAX. Is it how it should behave or am i missing something?
3. Last thing, and perhaps it is a feature request. Would it be possible to make echoed filter labels clickable, so that each label resets/clears the corresponding filter input?
This code show the labels of years checked checkboxes. What i mean is that years label will have a link and the click event will reset the years filter checkbox.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
We also use cookies to store items in your cart as well as allowing your to login on the site.
You can adjust all of your cookie settings by navigating the tabs on the left hand side.
By continuing to use this site, you also agree to our Privacy Policy.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
*Other cookies used for logging in and cart functions will only be used when you use those features and cannot be disabled.
If you disable these cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!