0

I have setup a custom post type with a custom taxonomy as categories.

I need to use get_the_terms or wp_get_post_terms to return the first category of a post in the custom post type.

But I can't quite figure out how to use it in comparison to get_the_category.

0

Try this one please:

$terms = get_the_terms(); $term = reset($terms);

| improve this answer | |
0

Hello here is an example i have used :

<?php while ( have_posts() ) : the_post(); 

  $category = get_the_terms( $id, 'event_category' );
  //get First Category
  $firstCategory = $category[0];
  //get category link
    $category_link = get_category_link($firstCategory->term_id);
    //echo category name
    echo $firstCategory->name;

 endwhile;
?>   

change event_category with your taxonomy slug

| improve this answer | |
  • You are welcome , vote my my answer if it was helpful for you :) – Roland Allla Nov 4 '16 at 12:24

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.