2

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!!!

7

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;
| improve this answer | |
3

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

| improve this answer | |
  • Please clean up your code. There's the WYSIWYG editor for formatting. – kaiser Jul 28 '15 at 11:56

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.