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

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?


share|improve this question
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 Feb 18 '11 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 Feb 23 '11 at 7:00

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.

share|improve this answer

What about using get_terms()?

Quick example:

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

foreach ( $terms as $term ) {
   echo $term->name.'<br />';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.