Get only the first term by taxonomy

Maybe it’s a stupid question but I can’t find the answer.

I have a custom taxonomy (directores) and each director is a term. Some times a film has more than one director. I need to print only the first director no all directors from one film.

Read More

Thanks!!!

Related posts

Leave a Reply

3 comments

  1. how about use get_the_terms() function?

    please try this code

    $directores = get_the_terms( $post->ID, 'directores' ); 
    $director = $directores[0];
    
    // print object from first director
    print_r($director);
    
    // or get the director name
    echo $director->name;
    
  2. use this code for access first texonomy from custom post type in wordpress

    how about use get_the_terms() function?

    please try this code

    $works = get_the_terms( $post->ID, ‘work’ );
    $director = $works[0];

    // print object from first director
    print_r($director);

    // or get the director name
    echo $director->name;