Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a custom post type named 'projects' with link custom taxonomy named 'projects'. I have added the five different project categories with this project taxonomy with two level of hierarchy custom post type ui. I tried to find function to get these five categories with taxonomy name 'projects' but i did not get the solution. Can anyone help me out how to get the list of these categories created with taxonomy named 'projects'. Any help will be appreciated.

Thanks in advance

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You will want to use get_terms. The following code show you how to access the terms. Please see the Codex page for get_terms for more information about the args that you can send to the function. I also show all of the data that is returned in the array of objects.

// Set your args
$args = array(
    'hide_empty' => 0   // Show terms that are not associated with any posts
);

// Get the terms
$projects = get_terms('projects', $args);

// Loop through and use terms
foreach($projects as $project)
{
    echo 'Term ID ' . $project->term_id;
    echo 'Name: ' . $project->name;
    echo 'Slug: ' . $project->slug;
    echo 'Term Group ' . $project->term_group;
    echo 'Term Taxonomy ID: ' . $project->term_taxonomy_id;
    echo 'Taxonomy: ' . $project->taxonomy;
    echo 'Description ' . $project->description;
    echo 'Parent: ' . $project->parent;
    echo 'Count: ' . $project->count;
}
share|improve this answer
    
Thank you so much it worked .. Actually I tried this one too but did not work may be there was some problem with my code... Thanks again –  user478 Aug 23 '11 at 2:54
    
The hide_empty=0 can make or break you. Intuitively, most people expect this to automatically return all of the terms; however, by default it only gets terms that are associated with posts. –  tollmanz Aug 23 '11 at 14:16
add comment

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.