I’ve got some pages with a custom taxonomy for each page and i’m trying to retrieve this taxonomy on the page. I’d basically need something like the_current_taxonomy()
like the_title()
. This has to run outside the loop cos i’ll use it in a custom WP_Query
right after.
Edit: Found a solution using a different way to retrieve the information i needed. Thanks for your help guys.
Like Rarst, I am confused what you want to output, the taxonomy or the terms of that taxonomy.
Taxonomy can be output for example if you make a template file with the name of that taxonomy: taxonomy-name.php
the title of the taxonomy then becomes:
The terms within a taxonomy can be output with a tagcloud, see http://codex.wordpress.org/Function_Reference/wp_tag_cloud (but that is within the loop)
I assume
taxonomy
is the same and what you need areterms
in that taxonomy, assigned to the post?Low level function for this is
wp_get_object_terms()
. It does need object’s ID so if you are resetting post data then you will need to store that from earlier or dig out of original query ($wp_query->get_queried_object_id()
as far as I remember).If you’re already on the category/term page you can call
get_queried_object();
before running your custom query to get category/term info, including slug.So, i needed to extract the term of a know taxonomy given to a page (like this:
(produtos being a custom post type, just for info.)).
I tried various things, among them, this:
get_terms('prod-categoria','')
This, works, but gives me everything about my taxonomy prod-categoria, which isn’t what i needed.Then as explained in the codex, two (interesting for me) parameters are available for
get_terms()
: child_of and parent. This sounded perfect, so i went:get_terms('prod-categoria','child_of=marca');
and alsoget_terms('prod-categoria','parent=marca')
, marca being a term parent (from the custom taxonomy prod-categoria) from which i wanted to extract the child terms. Both gave me no results. I also tried with the name Marca and the slug marca, nothing.The solution i ended up with is this:
$tt = the_title('','',false);
. I’m getting the page title to use it as a parameter after:$posts = posts_search ('produtos',array('prod-categoria'=>$tt,'prod-cols'=>'5-C-P-F-NF-P')); if($posts) { echo "<table class="table-marca">"; foreach($posts as $post) { ... }
Btw, the function posts_search() (found it on http://wordpress.stackexchange.com or http://stackoverflow.com if i’m right, don’t remember for sure) allows to do queries on multiple taxonomies.
I agree very much that it’s far away from being perfect, the title of the page having to be equal to the taxonomy name, but in my case it works. Thanks a lot to Rarst and Piet for trying to help.