logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
Display only first category of custom taxonomy

Hi All,

I've created a custom taxonomy (categories) to organise my custom post type (news). In my theme, I'd like to display what category a post belongs to.

Simple enough using
get_the_term_list 
I know, but my problem is that some posts are assigned to multiple categories and I only want to show one of them. Just the first category it was assigned to is fine.

I used to do this like so using the built-in category system but I can't figure out how to do it with my custom taxonomy.
<?php $category = get_the_category(); echo $category[0]->cat_name; ?>


Any ideas? Thanks.

This question has been answered.

oh_hello | 02/21/11 at 1:08pm Edit


(1) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    02/21/11
    1:46pm
    John Cotton says:

    You could try


    $categories= wp_get_object_terms($post->ID, 'categories');
    echo $categories[0]->name;

    Previous versions of this answer: 02/21/11 at 1:24pm

    • 02/21/11 1:46pm

      oh_hello says:

      That appears to do the trick. Thanks.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.