Forums › Forums › Search & Filter Pro › Check if a select list data is selected
- This topic has 18 replies, 2 voices, and was last updated 7 years, 9 months ago by Anonymous.
-
Anonymous(Private) February 22, 2017 at 11:33 am #91907
Hello,
I’d like to know if it’s possible to check if a user let a select list by default or if he selects something in.
For example, i have a author select list. Is it possible to have a snippet like this :
if (author_list_no_item_selected())
{ // do something }
else
{// do something }Thank you for your help.
Best regards.
Trevor(Private) February 22, 2017 at 8:30 pm #92086Do you mean to check before showing the results? If so, you can use the Edit Query Arguments filter to grab the filter arguments, see whether the author is set to (if set) and execute whatever code you need to.
This post by Ross gives some examples that might be useful.
Anonymous(Private) February 23, 2017 at 9:04 am #92230Hi Trevor,
In fact, i’ve a search.php file for my results. I wrote this code which appears on the top of the results :
global $searchandfilter; global $post; $author_id = $post->post_author; $author = get_the_author_meta('display_name', $author_id); $sf_current_query = $searchandfilter->get(802)->current_query(); $num_res = $wp_query->post_count; echo $sf_current_query->get_field_string("_sft_category").'<br />'; echo $sf_current_query->get_field_string("_sft_thematique").'<br />'; if($num_res == 0) { echo 'Terme(s): '.$sf_current_query->get_search_term().'<br />'; } echo 'Elément(s) trouvés(s): ' .$wp_query->found_posts;
I can display the author which is selected from the author select list but i don’t want to display anything if no author selected.
I need a valid snippet which might be :
if ($author_id != '0') { echo $author.'<br />'; }
Thank you for your help.
Best regards.
Anonymous(Private) February 23, 2017 at 1:39 pm #92386If i don’t select author and use :
if ($author != '') { echo $author.'<br />'; }
It displays the last author of the authors list.
If i select or don’t select author and use :
if (!isset($author)) { echo $author.'<br />'; }
It displays nothing.
I can’t see how make it work.
Best regards
-
AuthorPosts