Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 Answers

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.

share|improve this answer
add comment
up vote 1 down vote accepted

So, i needed to extract the term of a know taxonomy given to a page (like this:

function register_prod_categoria() {

register_taxonomy( 'prod-categoria', array( 'produtos', 'page' ),

(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 also get_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, dont 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.

share|improve this answer
add comment

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:

<h1 class="page-title"><<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h1>

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)

share|improve this answer
    
The objective is to output the term from a taxonomy allocated to the current page. So i tried to echo the terms within my taxonomy with wp_tag_cloud() and it worked, i can see the one i need to output in the middle. Then i tried to use the get_term_by() function you gave me but with no success. –  kevin Jan 6 '11 at 15:36
    
I also tried to change the second parameter to $post->ID as shown in the codex.wordpress.org/Function_Reference/get_term_by#Examples example on the codex page, but no success either. –  kevin Jan 6 '11 at 15:41
add comment

I assume taxonomy is the same and what you need are terms 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).

share|improve this answer
    
Yes as i wrote in a comment above, i need to extract a term from a taxonomy assigned to the page to then use it as a parameter in my new WP_Query(). The problem of wp get object terms() is that is requires a taxonomy as a parameter. –  kevin Jan 6 '11 at 15:39
    
@kevin I assume if it's your own custom taxonomy you know what it is to use as parameter? Or you want all terms in all taxonomies assigned to the post? Please clarify. –  Rarst Jan 6 '11 at 15:49
    
Yes it's my own, but i explained myself pretty bad, i wanted to find the term allowed to a certain taxonomy that i know which is also related to the page. Sorry for not being so clear. –  kevin Jan 7 '11 at 13:36
    
@kevin I still don't get it... please update your question with some specific example of what exactly you have and what you want to retrieve –  Rarst Jan 7 '11 at 15:29
    
@Rarst, problem solved, i edited my first post. –  kevin Jan 7 '11 at 17:01
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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