My site is built in such a way that every single post (in a custom post type) is accessed via a category archive (custom taxonomy). Every post may have more than one category assigned, but I want to display only the category from the archive that came previously.

Lets say post "Bob Brooks" is assigned cat apple, banana and carrot. I browse to site.com/category/carrot/ and click on the result "Bob Brooks". on site.com/bob-brooks/, I want it to show "carrot" in a subheader on the template, but not the other categories. And I obviously want it to show the correct cat dynamically.

How do I do that?

  • I am not sure if there is any other good way or not, but you can use session. Commented May 22, 2014 at 20:38
  • I actually figured out the answer on my own. The site generates a cookie on the initial search field to save a person's search term, and that term is the info I need. So I just set the cookie value as a php variable and stick it where I need it. Probably not the best method, but it's working nicely. Commented May 22, 2014 at 20:55

1 Answer 1


I am not sure if there is a simple way to do that, but one solution which can work is get an HTTP referrer and parse it to get the category name.

In PHP you can get a referrer like this - $_SERVER['HTTP_REFERER']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.