Forums › Forums › Search & Filter Pro › Accessing Field slug on search results
- This topic has 4 replies, 2 voices, and was last updated 6 years, 7 months ago by Trevor.
-
Anonymous(Private) March 30, 2018 at 12:11 pm #169166
Just a quick question that I haven’t been able to find the answer to – I’m customising my results page to only display certain text etc if a search field has a value (see below) and I’d like to be able to access the slug for a certain field (exactly how it is in the search url) so I can load an image based upon this value.
Full code is below, ideally I need something along the lines of:
$brand = $sf_current_query->get_fields_html( array("_sft_pwb-brand"), $args ); if(!empty($brand)){echo '<img src="'. $brand .'.png">';}; echo '</p>';
But with the brand-slug rather than “Brand Name”?
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1446)->current_query(); $args = array( "str" => '%2$s', "delim" => array(", ", " - "), "field_delim" => ' ', "show_all_if_empty" => false ); echo '<p>All '; echo $sf_current_query->get_fields_html( array("_sft_pa_size","_sft_product_cat"), $args ); $colour = $sf_current_query->get_fields_html( array("_sft_pa_colour"), $args ); if(!empty($colour)){echo ' in '. $colour;}; $brand = $sf_current_query->get_fields_html( array("_sft_pwb-brand"), $args ); if(!empty($brand)){echo ' by '. $brand;}; echo '</p>'; ?>
Thanks in advance 🙂
Anonymous(Private) March 30, 2018 at 1:42 pm #169183Thank you Trevor – this outputs:
Array ( [_sft_product_cat] => Array ( [name] => Product categories [singular_name] => Category [all_items_label] => All categories [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 128 [name] => Men's Shoes [value] => mens-shoes [count] => 0 ) ) ) [_sft_pwb-brand] => Array ( [name] => Brands [singular_name] => Brand [all_items_label] => All Brands [type] => taxonomy [active_terms] => Array ( [0] => Array ( [id] => 220 [name] => Ted Baker [value] => ted-baker [count] => 0 ) ) ) )
And the bit I need is the “value” of “_sft_pwb-brand” – i.e. “ted-baker”
Thanks in advance 🙂
Anonymous(Private) March 30, 2018 at 1:56 pm #169189I think I’ve sorted it thanks Trevor – sorry to mess you around!
If anyone else needs it, the code is as follows:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1446)->current_query(); $array_data = $sf_current_query->get_array(); $typeOfSearch = $array_data["_sft_pwb-brand"]["active_terms"][0]["value"]; echo $typeOfSearch ; ?>
Where _sft_pwb-brand is the field you need, and 1446 is the ID of the search form.
-
AuthorPosts