Forums › Forums › Search & Filter Pro › Adding a comma after the search term when filters are also being used
- This topic has 2 replies, 2 voices, and was last updated 6 years, 8 months ago by Anonymous.
-
Anonymous(Private) March 6, 2018 at 5:41 am #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!
ConnieTrevor(Private) March 6, 2018 at 11:09 am #164127Ah, 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?
-
AuthorPosts