add the taxonomy value in the search template

Forums › Forums › Search & Filter Pro › add the taxonomy value in the search template

Viewing 7 posts – 1 through 7 (of 7 total)
  • Anonymous
    #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/kmqfp4a

    as you can see i need to complete the field “Giorno:…” (under the main title) with my taxonomy value.

    thank you…

    Anonymous
    #5200

    any help? ๐Ÿ™

    Ross Moderator
    #5239

    Ah 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
    #5894

    thank 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
    #5938

    Hey Simona

    I’m away atm but will reply on my return – just a couple more lines of code ๐Ÿ™‚

    Thanks

    Ross Moderator
    #6257

    Here 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");
    Anonymous
    #7029

    thank you Ross!

Viewing 7 posts – 1 through 7 (of 7 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.