Forums › Forums › Search & Filter Pro › How to make filter label appears in the search field
- This topic has 11 replies, 2 voices, and was last updated 6 years, 10 months ago by Anonymous.
-
Anonymous(Private) February 21, 2018 at 7:56 am #161145
Hello,
I use a search field and several checkbox to filter my posts and when I check one or several checkbox I would like the checkbox labels appears in the search field.
It’s possible to make it appears in the URL like in your demo (http://demo.designsandcode.com) but I want it in the search field.Can you help me ?
Thank you,
Best regards
JukeTrevor(Private) February 21, 2018 at 9:11 am #161167With some PHP coding on your part, yes you can display the query on the page. Note, if you are using Ajax to refresh the page, any such output of the query needs to be inside the Ajax container.
The documentation is here:
https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/
There are many snippets also on this forum. Try this search:
https://support.searchandfilter.com/forums/search/current_query/
You need to fetch the values from any form fields, and the search terms (they are held separately). The code to find and display taxonomies is different to that of custom fields, and be aware that some search terms will be held as arrays, and not single strings/values.
Anonymous(Private) March 2, 2018 at 2:09 pm #163253Hello,
In my search form UI I have a search form and multiple post meta acf checkbox
I tried :
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(53)->current_query();
echo $sf_current_query->get_search_term();
?>It display only search terms of the search form, not post meta acf checkbox one !
So I tried :
<?php
global $searchandfilter;
$sf_current_query = $searchandfilter->get(53)->current_query();
$args = array(
“str” => ‘%2$s’,
“delim” => array(“, “, ” – “),
“field_delim” => ‘, ‘,
“show_all_if_empty” => false
);echo $sf_current_query->get_fields_html(
array(“_sf_s”, “_sfm_nom-de-l-artiste”, “_sfm_prenom-du-commissaire”, “_sfm_lieu”, “_sfm_nom-du-medium”, “_sfm_forme-de-la-carte”, “_sfm_couleur”, “_sfm_ecole-du-commissaire”, “_sfm_jour-de-la-visite”, “_sfm_age-du-commissaire”),
$args
);
?>But it displays nothing !
Can you help me and telle me what I did wrong ?
Thank you very muche
Best regards,
JukeTrevor(Private) March 2, 2018 at 4:57 pm #163328I am not sure, but a good place to start is to echo the entire query array to the screen so you can see what everything is. Like this:
$sf_current_query = $searchandfilter->get(53)->current_query(); echo '<pre>'; print_r($sf_current_query->get_array()); echo '</pre>';
Anonymous(Private) March 2, 2018 at 5:10 pm #163335Thank you ! Yes you’re right it displays the entire query ! How to keep only all the [value] results ?
Array
(
[_sfm_prenom-du-commissaire] => Array
(
[name] =>
[singular_name] =>
[all_items_label] =>
[type] => post_meta
[active_terms] => Array
(
[0] => Array
(
[name] => Anaëlle T.
[value] => Anaëlle T.
))
)
[_sfm_jour-de-la-visite] => Array
(
[name] =>
[singular_name] =>
[all_items_label] =>
[type] => post_meta
[active_terms] => Array
(
[0] => Array
(
[name] => Jeudi
[value] => Jeudi
)[1] => Array
(
[name] => Lundi
[value] => Lundi
))
)
)
-
AuthorPosts