-
Search Results
-
I have a filter form that automatically submits as the user selects filter parameters, and displays loads via AJAX. That’s working fine but I can’t seem to get the search data to return the correct values when the search results update.
I would like to output something like this:
Travel Month: January
Destinations: Grand Canyon, Las Vegas
Activities: Great for Kids, PhotographyHere is my JS script:
(function($){ $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); $.ajax({ type: "POST", url: "/wp-admin/admin-ajax.php", data: { action: 'filterParams'} }).done(function( response ) { $( ".parameters" ).html( response ); }); }); })(jQuery);And here is the PHP script that I put in functions.php:
function filterParams(){ global $searchandfilter; $sf_current_query = $searchandfilter->get(12192)->current_query(); $args = array( "str" => '%1$s: %2$s', // this is the format of the string generated for each field "delim" => array(", ", " - "), "field_delim" => '<br />', "show_all_if_empty" => true ); echo $sf_current_query->get_fields_html( array("_sft_travelmonth","_sft_destination", "_sft_activities"), $args ); } add_action('wp_ajax_filterParams', 'filterParams'); add_action('wp_ajax_nopriv_filterParams', 'filterParams');This is what is always getting returned in the AJAX call:
Travel Months: All Travel Months
Destinations: All Destinations
Activities: All Activities0When I use:
var_dump($sf_current_query->get_array());
instead of:echo $sf_current_query->get_fields_html( array("_sft_travelmonth","_sft_destination", "_sft_activities"), $args );It returns an empty array:
array(0) { } 0I’ve confirmed that the form ID is correct.
What am I missing here?Topic: Display multiple terms
I’ve been crunching through the forum, but not seeing an answer.
– – – – – – – –
I’m using the following code to display a list of current terms for the filtered search:
</php global $searchandfilter; $sf_current_query = $searchandfilter->get(99801)->current_query()->get_array(); echo '<strong>Filters</strong>'; if ( empty($sf_current_query ) ) { echo ' • ' . "All" . "<br />"; } else { foreach($sf_current_query as $key) { echo ' • ' . $key['active_terms'][0]['name'] . ' '; } } echo "<br /><br />"; ?>– – – – – – –
My filter includes dropdowns and checkboxes. For example:
Market (dropdown)
FloridaCuisines (checkboxes)
[ ] American
[X] Caribbean
[ ] Italian
[X] Mexican– – – – – – –
The code works and the list displays, but it only shows one of the selected checkbox terms…
Filters • Florida • Mexican
Instead of…
Filters • Florida • Caribbean • Mexican
OR.. Filters • Florida • Caribbean, MexicanI suspect that an array is required, but not sure what/where/how.
Please help this newbie out.
Thanks!