0

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!

  • 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
  • 1
    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
2

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

| improve this answer | |
0

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.

| improve this answer | |
  • 1
    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
0

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>'; }
 ?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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