WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
    
possible duplicate of Get the first Category / Term only in single-custom-post.php – Pieter Goosen Jul 28 '15 at 8:21

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

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

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;

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

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.