Hi
It should look like this a bit, I think:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1726)->current_query();
if ($sf_current_query->is_filtered()) {
// do the loop
} else {
// do something else
}
AnonymousInactive
Thanks Trevor!
I am using a theme I started from underscores template
Installed the results.php template and I am trying to use the github code here as reference.
but no luck yet..
Any chance you can guide me a bit further?
Where do I place the following code in my results.php if it needs to be before the “have_posts” loop?
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1726)->current_query();
echo $sf_current_query->is_filtered();
Hi Adam
S&F doesn’t search tag names, nor does the default WP search – try your “Flowers” test with the old search and you will see (you can search tag names by combining S&F with Relevanssi).
RE the input box, thats the last step we missed!
So, each of the search input fields, that you have changed to be renamed to _sf_s
, also has a value
attribute.
<input type="text" placeholder="<?php _e( 'Search', 'squarecode' ); ?>" value="<?php echo $searchresults; ?>" name="_sf_s" id="s" />
we need to get the S&F search term into this value attribute. I can see in both your header and search templates, that the query is populated with the value from this line:
<?php $searchresults = get_search_query(); ?>
So all we need to do is get S&F search query into that variable – from the docs you would replace the code above with –
<?php
//Get the search term
//replace <code>4243</code> with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(4243)->current_query();
$searchresults = $sf_current_query->get_search_term();
?>
Thanks
AnonymousInactive
I finally found this solution:
$sarr = $sf_current_query->get_array();
$author = $sarr[authors][active_terms][0][name] ;
$fromDate = $sarr[_sf_post_date][active_terms][0][value] ;
$toDate = $sarr[_sf_post_date][active_terms][1][value];
I hope it keeps on working always!
AnonymousInactive
Hi!
Sorry for my late reply but I had to complete another project..
If I do a var_dump I get the following:
array(2) { [“authors”]=> array(5) { [“name”]=> string(7) “Authors” [“singular_name”]=> string(6) “Author” [“all_items_label”]=> string(11) “All Authors” [“type”]=> string(9) “post_type” [“active_terms”]=> array(1) { [0]=> array(3) { [“id”]=> int(39) [“name”]=> string(7) “Agenzie” [“value”]=> string(7) “agenzie” } } } [“_sf_post_date”]=> array(1) { [“active_terms”]=> array(2) { [0]=> array(1) { [“value”]=> string(8) “01032016” } [1]=> array(1) { [“value”]=> string(8) “16032016” } } } }
In my form I have Authors (in this example value for that is “Agenzie”) and Post Date range fields.
I am not expert in PHP…can you help me to get the authors and post date range?
As $sf_current_query->get_field_string(“authors”) does not work.
Thanks
AnonymousInactive
Hi, How would I display the sort order in a way similar to displaying categories or tags? Here’s the code I’m using, but only _sft_category and _sft_school display on my page.
$args = array(
"str" => '<strong>%1$s</strong>: %2$s',
"show_all_if_empty" => false
//"field_delim" => '<hr />'
);
echo $sf_current_query->get_fields_html(array("_sft_category", "_sft_school", "sort_order"), $args);
Here’s a link to the test page:
http://staging.cudenvertoday.org/articles
Thanks!
what happens if you var_dump the array:
<?php
//Get a single fields values using labels
//replace 1526 with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(147)->current_query();
var_dump($sf_current_query->get_array());
?>
CAn you paste the output here?
Thanks
AnonymousInactive
Website is actually offline.
I just put in page template:
<?php
//Get a single fields values using labels
//replace 1526 with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(147)->current_query();
echo $sf_current_query->get_field_string(“_sfm_xxx”);
?>
and Its echo nothing. I’m using ACF fileds
AnonymousInactive
Im trying something like and its not working
<?php
//Get a single fields values using labels
//replace 1526
with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(147)->current_query();
echo $sf_current_query->get_field_string(“_sfm_xxx”);
?>
Url looks like this:
http://www.xxx.com/?_sfm_xxx…
Hi Scott
To answer your questions:
1) To get data from the current search you can use:
http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/
So, from that link, the code would be
<?php
//Get the search term
//replace '1526' with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(1526)->current_query();
echo $sf_current_query->get_search_term();
?>
2) Which display method are you using? If you are using archive
then it sounds like you have set your template up wrong (a little). This really depends on your theme, so go into your theme and take a look at other template files such as archive.php
or search.php
.
Usually you should at least be starting with a get_header()
and finishing with a get_footer()
– but this is really theme dependent – https://codex.wordpress.org/Include_Tags
Thanks