-
AuthorSearch Results
-
October 7, 2019 at 3:15 pm #223002
In reply to: Accessing the Search Data
TrevorParticipantTo 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.
October 4, 2019 at 12:53 pm #222869In reply to: You searched for (including filters)?
TrevorParticipantTo 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 use this to display the filter array:
<?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.
July 5, 2019 at 4:04 pm #215649
TrevorParticipantTo 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 use this to display the filter array:
<?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.
June 5, 2019 at 9:27 am #213328In reply to: i want to get the current active filter sort label
TrevorParticipantYou can find more details from the filter query array.
You may need to temporarily output the array to see how to access the term that you want.
If you add this code to the page, it will output the entire array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>
January 8, 2019 at 2:37 pm #198357In reply to: Cannot filter on custom wp post
AnonymousInactiveWell I might have asked wrong way 🙂
The thing is the filter as I call it with the shortcode shows up, but if I try to filter results (e.g. I select one region in the dropdown or white a text to the search input and press submit), nothing changes – the result set of $trainers remains unchanged (unfiltered), so as the $GLOBALS[‘wp_query’]->request).
From your first link you provided, I tried this code:
$sf_current_query = $searchandfilter->get(1513)->current_query(); echo '<pre>'; print_r($sf_current_query->get_array()); echo '</pre>';
and got
array (size=10) 'paged' => int 1 'search_filter_id' => int 1513 'search_filter_override' => boolean false 'posts_per_page' => int 10 'post_status' => array (size=1) 0 => string 'publish' (length=7) 'meta_query' => array (size=0) empty 'post_type' => string 'trainer' (length=7) 'is_search' => boolean true 'is_archive' => boolean true 'post__in' => array (size=7) 0 => int 1284 1 => int 1495 2 => int 1503 3 => int 1504 4 => int 1505 5 => int 1506 6 => int 1508
(notice there is no sign of filtering in the array). This is my main problem.
June 25, 2018 at 12:31 pm #181171In reply to: Sort order – different query
TrevorParticipantYou could use PHP to look at the array that holds the filter arguments, and conditionally load different code in the same template. Again, that is custom coding.
To start with, put this code on the results page in a suitable place:
$sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array(); echo '<pre>'; print_r($sf_current_query_array); echo '</pre>';
CHANGE THE ID NUMBER in the above code (1446) to whatever the ID of you form is.
You will then see the array of filters used, and you can figure than how to fetch the value you need to add PHP to your template to test what the user has selected.
May 17, 2018 at 7:25 am #178123In reply to: Get Count of Filters
TrevorParticipantPlease note that, as your license has expired, you will first need to renew at the (discounted) renewal price to receive support.
Does this code show anything different?
$sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array(); echo '<pre>'; print_r($sf_current_query_array); echo '</pre>';
You will need to change the ID number of course. There are some threads on the forum that you can search for where other users have used this code to access the filters data.
April 23, 2018 at 8:53 pm #173884In reply to: Select Box Like Ted
AnonymousInactiveThanks!
Got it working using the links you supplied.
$sf_current_types_query = $searchandfilter->get(299)->current_query()->get_array(); $currentType=$sf_current_types_query['post_types']['active_terms'][0]['name']; if ( empty($currentType) ) { echo ''; } else { echo '<li>' . $sf_current_types_query['post_types']['active_terms'][0]['name'] . '<i class="fa fa-times"></i></li>'; } ?>
April 23, 2018 at 7:08 am #173724In reply to: Select Box Like Ted
TrevorParticipantAssuming that
Post Type
is one of the search fields, it should work in exactly the same way. If it does not, you need to print out the entire search/filter array and examine the structure, like this:$sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array(); echo '<pre>'; print_r($sf_current_query_array); echo '</pre>';
Change the ID accordingly for your form.
And then check to see if the terms you need are contained in that.
April 12, 2018 at 11:07 pm #171986In reply to: Display multiple terms
AnonymousInactiveTrevor, thanks again for spending time with me today. I really appreciated it.
Good news, I finally figured it out!
Here’s the happy code:
<?php global $searchandfilter; $args = array( "str" => '%2$s', "delim" => array(", ", " - "), "field_delim" => ', ', "show_all_if_empty" => false ); $sf_current_query = $searchandfilter->get(99801)->current_query()->get_array(); $sf_current_style_query = $searchandfilter->get(99801)->current_query()->get_fields_html(array("_sft_style", "_sft_name"),$args); $sf_current_cuisine_query = $searchandfilter->get(99801)->current_query()->get_fields_html(array("_sft_cuisine", "_sft_name"),$args); echo '<strong>Filters</strong>'; if ( empty($sf_current_query ) ) { echo ' • ' . "All" . "<br /><br />"; } else { echo ' • ' . $sf_current_query['_sft_category']['active_terms'][0]['name'] . ' • ' . $sf_current_query['_sfm_wpcf-location-city']['active_terms'][0]['name'] . ' • ' . $sf_current_style_query . ' • ' . $sf_current_cuisine_query; echo "<br /><br />"; } ?>
Cheers!
-
AuthorSearch Results