The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
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?
Please let me know. thank you.
add_action( 'wp_ajax_show_active_filters', 'show_active_filters' );
add_action( 'wp_ajax_nopriv_show_active_filters', 'show_active_filters' );
function show_active_filters(){
global $searchandfilter;
$sf_current_query = $searchandfilter->get(8175)->current_query()->get_array();
ob_start();
echo '<span class="active-pill">'.$sf_current_query['_sft_contest-years']['active_terms'][0]['name'].'</span>';
$ajax_filters_html .= ob_get_contents();
ob_end_clean();
echo json_encode(array('html'=>$ajax_filters_html));
wp_die();
}
Hi Trevor,
I am not using a page builder or anything. I am using a CPT archive page and everything works fine. Even the results of “$searchandfilter->get(ID)->current_query()” are shown ON PAGE RELOAD which I’m trying to avoid since I want to load the results using AJAX.
Here is a screenshot of what I’m trying to achieve along with the use case:
https://share.getcloudapp.com/rRu7ZZzl
– When a user selects a Year -> this would add an active filter pill with the selected year (example: 2020) – Same goes for the rest of the filters and the search input field.
– When a user hits the X on the active filter pill, it needs to remove that from the filters and resubmits the form.
Thank you in advance!
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).
Please let me know if this is doable?
© 2024 Search & Filter Support. All Rights Reserved.
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 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.
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!
More information about our Cookie Policy