Forums Forums Search & Filter Pro Adding a comma after the search term when filters are also being used

Viewing 3 posts - 1 through 3 (of 3 total)
  • Anonymous
    #164067

    Hi there,

    First of all, this plugin has absolutely saved my life and I’m about to purchase the developer license so I can use it on all my client sites moving forward.

    However, I had a small little quandary. I’ve set up a custom search form that offers both a search bar as well as three filterable dropdowns.

    I’ve subsequently created a search results page that when queried returns results as well as a title that says:

    # for [search term(s)]

    (with the # being the number of search results for the term(s)).

    Now with this:

    <?php global $searchandfilter;
        $sf_current_query = $searchandfilter->get(2398)->current_query();
        $searchTerm = $sf_current_query->get_search_term();
          $args = array(
          "str"           => '%2$s', 
          "delim"         => array(", ", " - "), 
          "field_delim"       => ', ', 
          "show_all_if_empty"     => false 
        );
      ?>
    
    <?php global $wp_query;
              echo $wp_query->found_posts; ?>
              Search Results for <?php echo $searchTerm; ?> <?php echo $sf_current_query->get_fields_html( array("_sft_clinical-area", "_sft_program", "_sft_type"), $args);?>

    I’ve been able to output the search terms quite nicely, save for my one quandary. That if both a search term and filter are used, there is no comma between the two. I know this must be something easy that I’m missing, but I can’t seem to figure it out! Any help would be greatly greatly appreciated.

    Cheers!
    Connie

    Trevor
    #164127

    Ah, I see. You have three possible output combinations.

    Try this:

    <?php global $searchandfilter;
        $sf_current_query = $searchandfilter->get(2398)->current_query();
        $searchTerm = $sf_current_query->get_search_term();
          $args = array(
          "str"           => '%2$s', 
          "delim"         => array(", ", " - "), 
          "field_delim"       => ', ', 
          "show_all_if_empty"     => false 
        );
      ?>
    
    <?php global $wp_query;
    $fields_html = $sf_current_query->get_fields_html( array("_sft_clinical-area", "_sft_program", "_sft_type"), $args);
        if (( $searchTerm <> "" ) && ( $fields_html <> "" ) ){
          $field_delim = ', ';
        } else {
          $field_delim = '';
        }
    
              echo $wp_query->found_posts; ?>
              Search Results for <?php echo $searchTerm . $field_delim . $fields_html; ?>

    Maybe?

    Anonymous
    #164399

    That’s it! Thanks so much, Trevor!

Viewing 3 posts - 1 through 3 (of 3 total)