Forums › Forums › Search & Filter Pro › add the taxonomy value in the search template
Tagged: taxonomy value
- This topic has 6 replies, 2 voices, and was last updated 10 years ago by Anonymous.
-
Anonymous(Private) September 25, 2014 at 2:32 pm #5048
hy, i need to add the value of my taxonomy in the search page.
i see it in the url, like “?_sft=…” but i wonder which code i should add on my search template in order to view the taxonomy value together with the search results.can you help me please?
this is my results page (search template):
http://tinyurl.com/kmqfp4aas you can see i need to complete the field “Giorno:…” (under the main title) with my taxonomy value.
thank you…
Ross Moderator(Private) September 29, 2014 at 10:37 pm #5239Ah you want to display the taxonomy name in the current page?
Then you need to use some code like this in your template:
function get_taxonomy_values($taxonomy_key) { global $wp_query; if(isset($wp_query->query[$taxonomy_key])) { if (strpos(esc_attr($wp_query->query[$taxonomy_key]),',') !== false) { $ochar = ","; $taxterms = explode($ochar, esc_attr(($wp_query->query[$taxonomy_key]))); return implode(" or ", $taxterms); } else { $ochar = "+"; $taxterms = explode($ochar, esc_attr(urlencode($wp_query->query[$taxonomy_key]))); return implode(" and ", $taxterms); } } } echo get_taxonomy_values("_sft_giorni");
Hope that helps!
Anonymous(Private) October 13, 2014 at 4:16 pm #5894thank you. it works. but how can i view the name of the taxonomy, instead of the slug?
and one more question:
can you please tell me the code in order to view the category name (for a category search template)? i tried by replacing the last string:
get_taxonomy_values(“_sft_giorni”)
IN
get_taxonomy_values(“_sft_portfolio-category”)but it doesn’t work properly.
thank you very much for your help
Ross Moderator(Private) October 14, 2014 at 4:17 pm #5938Hey Simona
I’m away atm but will reply on my return – just a couple more lines of code ๐
Thanks
Ross Moderator(Private) October 21, 2014 at 6:30 pm #6257Here is the updated code ๐
function get_taxonomy_values($taxonomy_key) { global $wp_query; global $wpdb; if(isset($wp_query->query[$taxonomy_key])) { if (strpos(esc_attr($wp_query->query[$taxonomy_key]),',') !== false) { $ochar = ","; $taxterms = explode($ochar, esc_attr(($wp_query->query[$taxonomy_key]))); $taxlabels = array(); foreach ($taxterms as $taxterm) { $taxlabel = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE slug='".$taxterm."'"); array_push($taxlabels, $taxlabel); } return implode(" or ", $taxlabels); } else { $ochar = "+"; $taxterms = explode($ochar, esc_attr(urlencode($wp_query->query[$taxonomy_key]))); $taxlabels = array(); foreach ($taxterms as $taxterm) { $taxlabel = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE slug='".$taxterm."'"); array_push($taxlabels, $taxlabel); } return implode(" or ", $taxlabels); } } } echo get_taxonomy_values("_sft_giorni");
-
AuthorPosts