5

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.

Thanks!!!

1

3 Answers 3

8

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;
0
5

Finally I read the Wordpress doc Reference/get terms

$args = array('number' => '1',);
$terms = get_terms('director', $args );
foreach( $terms as $term ){
  echo  $term->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;

1
  • Please clean up your code. There's the WYSIWYG editor for formatting.
    – kaiser
    Jul 28, 2015 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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