Last active
March 9, 2017 19:09
-
-
Save rmorse/4c8931c1eb1056b6937a to your computer and use it in GitHub Desktop.
Search & Filter Pro - Active Query - Get multiple fields by passing an array of field names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Get a multiple fields values by passing an array of field names | |
//replace `1526` with the ID of your search form | |
global $searchandfilter; | |
$sf_current_query = $searchandfilter->get(1526)->current_query(); | |
/* | |
* EXAMPLE 1 | |
*/ | |
echo $sf_current_query->get_fields_html( | |
array("_sft_category", "_sft_post_tag") | |
); | |
/* will output: | |
Genres: Documentary, Family | |
Production Country: France | |
*/ | |
/* | |
* EXAMPLE 2 - with args | |
*/ | |
$args = array( | |
"str" => '%1$s: %2$s', // this is the format of the string generated for each field | |
"delim" => array(", ", " - "), // these are the delims between values of a field, first value is for regular field types, second value is for range fields | |
"field_delim" => '<br />', // the delim between fields | |
"show_all_if_empty" => false // if a field has not been selected/used, set to false to leave it out and list no value | |
); | |
echo $sf_current_query->get_fields_html( | |
array("_sft_sfdc_genre", "_sft_sfdc_production_country"), | |
$args | |
); | |
/* will output same as previous */ | |
/* | |
* EXAMPLE 3 - without labels for fields themselves (the `str` value has been changed to include only values) | |
*/ | |
$args = array( | |
"str" => '%2$s', | |
"delim" => array(", ", " - "), | |
"field_delim" => ', ', | |
"show_all_if_empty" => false | |
); | |
echo $sf_current_query->get_fields_html( | |
array("_sft_sfdc_genre", "_sft_sfdc_production_country"), | |
$args | |
); | |
/* will output: | |
Documentary, Family, France | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment