Forums Forums Search & Filter Pro Check if a select list data is selected

Viewing 10 posts - 1 through 10 (of 19 total)
  • Anonymous
    #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
    #92086

    Do 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
    #92230

    Hi 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&eacute;ment(s) trouv&eacutes(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.

    Trevor
    #92319

    The two ways I can see to do this are depending on what value is in $author if there is no author. Either:

    if ($author != '') {
      echo $author.'<br />';
    }

    or

    if (!isset($author)) {
      echo $author.'<br />';
    }

    Would be my guess.

    Anonymous
    #92386

    If 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

    Trevor
    #92391

    You mean the code you fist showed me did not show the selected author either?

    Anonymous
    #92397

    The first code i showed you :

    if ($author_id != '0') {
    	echo $author.'<br />';
    	}

    displays the author that i selected.
    But if i select nothing, it’s the name of a random author of the list which is displayed.
    I don’t understand.

    Anonymous
    #92399
    This reply has been marked as private.
    Trevor
    #92406

    Is it the name of the author of the first result on the results? (If you select no author)

    Anonymous
    #92427

    I can see the last author of the list if i select nothing…

Viewing 10 posts - 1 through 10 (of 19 total)