Hi, can you try this code (it might be a step backwards, but bear with me):
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query();
echo $sf_current_query->get_field_string("_sft_length", array("str" => "%2$s");
echo $sf_current_query->get_field_string("_sft_rate", array("str" => "%2$s");
echo $sf_current_query->get_field_string("_sft_guest", array("str" => "%2$s");
echo $sf_current_query->get_field_string("_sft_location", array("str" => "%2$s");
echo $sf_current_query->get_field_string("_sft_toy", array("str" => "%2$s");
AnonymousInactive
Hi,
I’ve added the code but it seems to be throwing an error on the array. Am I missing something?
<?php
//Get a multiple fields values by passing an array of field names
//replace 1526 with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query();
echo $sf_current_query->get_fields_html(array(), array(‘show_all_if_empty’ => false)
);
?>
I’ve also added the code from the supplied link but it throws back the following error:
array(2) { [“_sft_length”]=> array(5) { [“name”]=> string(13) “Yacht Lengths” [“singular_name”]=> string(12) “Yacht Length” [“all_items_label”]=> string(17) “All Yacht Lengths” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(6) [“name”]=> string(6) “40-50m” [“value”]=> string(6) “40-50m” [“count”]=> int(5) } } } [“_sft_toy”]=> array(5) { [“name”]=> string(15) “Yacht Hero Toys” [“singular_name”]=> string(14) “Yacht Hero Toy” [“all_items_label”]=> string(19) “All Yacht Hero Toys” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(16) [“name”]=> string(7) “Freezer” [“value”]=> string(7) “freezer” [“count”]=> int(5) } } } }
Found on the same web link as before.
AnonymousInactive
Hi,
I have used the following code to show the specific taxonomy fields within the search form:
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(339)->current_query();
echo $sf_current_query->get_fields_html(
array("_sft_length", "_sft_rate", "_sft_guest", "_sft_location", "_sft_toy")
);
?>
However this code displays the full list of fields continuously.
Is there a way to style and list only the content from each taxonomy used for a search, after form submission?
Further to this, once the content is displaying independently is there a way to assign a small “cross” to be able to remove this specific field from the search?
Page found at http://www.cascadetest.co.uk/oneocean.com/charter-overview/
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!
I am using Avada theme.
I found some posts and this helpful link to know how to display search terms on Title bar:
https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/
I added the following code:
global $searchandfilter;
$sf_current_query = $searchandfilter->get(8444)->current_query();
$sf_fields = $sf_current_query->get_fields_html(
array( “_sft_category”, “authors”, “post_date”)
);
$title = sprintf( __( ‘Search results for: %s’, ‘Avada’ ), get_search_query() . ‘ ‘ . $sf_fields );
It works for Category, but not for the other fields I have in the searcg form as Athors and post_date range.
This is the page with the Advanced Search:
http://www.amiciperlacitta.it/news/la-bussola/ricerca-avanzata/
Can you help me?
Waiting for your kind reply
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!