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 have a custom post type (dibujos) and 4 custom taxonomy.

I would like to get term name in a current post.

The probleme is, how to To display the name of the taxonomy, no matter what taxonomy is.

The code is:

<?php   // Get terms for post
 $terms = get_the_terms( $post->ID , 'my-taxonomy' );
 // Loop over each item since it's an array
 if ( $terms != null ){
 foreach( $terms as $term ) {
 // Print the name method from $term which is an OBJECT
 print $term->name ;
 // Get rid of the other data stored in the object, since it's not needed
 unset($term);
} } ?>

Thks!

share|improve this question
    
I don't really understand this - you know the name of your taxonomy - you're specifying it in the get_the_terms() call. What exactly do you want to do? –  anu Sep 5 '12 at 7:37
    
Hi, I have 4 different taxonomy. How to know the taxonomy in the current post? –  Aina Sep 5 '12 at 9:16
    
I think you need to reframe the question. The code sample you've picked specifically chooses terms from a single taxonomy. Do you want to get all terms from all taxonomies? –  anu Sep 5 '12 at 9:25
    
No, i need the current term, not all terms. THKS –  Aina Sep 7 '12 at 5:13
    
Your question makes no sense - please edit it to be very clear whether you want to know the name of the taxonomy or the term. –  anu Sep 7 '12 at 7:03
add comment

3 Answers

You can use wp_get_object_terms($object_ids, $taxonomies, $args) to get all terms from a defined set of taxonomies for an object

The $taxonomies parameter can be an array of taxonomy names.

http://codex.wordpress.org/Function_Reference/wp_get_object_terms

share|improve this answer
add comment

Hi, I have 4 different taxonomy. How to know the taxonomy in the current post?

Nope, you cannot get the taxonomy name on single.php. What are you trying to achieve with this? You probably need to look at a problem from a different angle.

share|improve this answer
    
Hi, I try to get a navigation path (like a breadcrumbs). For example: If i'm looking for a house i would like to put a link to see all houses. I try with $wp_query->queried_object->name but nothing happend. –  Aina Sep 7 '12 at 5:12
add comment

Opsss Sorry I made a mess.

Put this code by each taxonomy

<?php if( false != get_the_term_list( $post->ID, 'my-taxonomy' ) ) {
     echo '<li>'.(__('Ver más:')) . get_the_term_list($post->ID,'my-taxonomy', ' ', ' ', '' ).'</li>'; }
 ?>
share|improve this answer
add comment

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.