I have created custom post type 'Portfolio' also under this post type I have created Portfolio categories with following code

functions.php - following is the code for custom post type i have defined in functions.php page

 function demo_register_post_type() {
            register_post_type('Portfolio', array(
                'labels' => array(
                    'name' => __('Portfolio'),
                    'singular_name' => __('Portfolio'),
                    'add_new' => 'Add New Portfolio',
                    'edit_item' => 'Edit Portfolio',
                    'new_item' => 'New Portfolio',
                    'view_item' => 'View Portfolio',
                    'search_items' => 'Search Portfolio',
                    'not_found' => 'No Portfolio found',
                    'not_found_in_trash' => 'No Portfolio found in Trash',
                    'show_ui' => true,
                    'show_in_menu' => true,
                    'capability_type' => 'post',
                    'hierarchical' => false,
                    'rewrite' => true,
                    'query_var' => true
                'menu_position' => 6,
                'public' => true,
                'supports' => array(
                'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false ),
                'taxonomy' => array('category', 'post_tag')

        register_taxonomy( 'portfolio-category', 'Portfolio', array ('hierarchical' => true, 'label' => __('Portfolio Categories')));  // portfolio categories

Now I want to retrieve all the categories from this post type and display posts from the categories on page?

Please let me know how could I do this?


  • Why two different category taxonomies though? You have the custom portfolio-category taxonomy registered, but additionally you're enabling the regular category taxonomy for this post type to, eg. 'taxonomy' => array('category', 'post_tag'), do you need both?
    – t31os
    Commented Feb 18, 2011 at 12:11
  • Yes I need both categories as I want to add portfolio details to my portfolio categories and dont want to show portfolio categories on blog or some where else on site. Thats why I am using two categories.
    – user3277
    Commented Feb 23, 2011 at 7:00

3 Answers 3


What about using get_terms()?

Quick example:

$terms = get_terms('portfolio-category');

foreach ( $terms as $term ) {
   echo $term->name.'<br />';

to get the posts of your custom post type you need to query post_type and you can do it like so:

<?php query_posts(array( 'post_type' => 'Portfolio' )); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <div class="post">

 <!-- Display the Title as a link to the Post's permalink. -->
 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

 <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

  <div class="entry">
    <?php the_content(); ?>

  <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
 </div> <!-- closes the first div box -->

 <?php endwhile; else: ?>
 <p>Sorry, no posts matched your criteria.</p>
 <?php endif; ?>

Now if you want to get Portfolio post of a specific term in your custom taxonamy then add the taxonomy argument to the query_posts array like so:

<?php query_posts(array( 'post_type' => 'Portfolio','portfolio-category' => 'category-name' )); ?>

Hope this helps.


Try this code, it's work. Thank me later.

   $term_args = array(
                'post_type'              => 'portfolio',
                 'taxonomy'               => 'project-type',
                'hide_empty'             => true,
                'fields'                 => 'all'
   $term_query = new WP_Term_Query( $term_args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.