Get the current object being queried with get_queried_object() example
Print
0
Sometimes you may want acces to the current object being queried. In my case I was working with a category archive and the URL looked something like: http://my_domain.com/archives/category/apples As part of my code I wanted to say: "These are the archived posts for: Apples"
The solution was to use the function: get_queried_object() See Wordpress Codex for more info. Example:
echo 'These are the archived posts for ' . get_queried_object()->name;
If you need the slug use: get_queried_object()->slug