WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Since two days I am trying to solve a problem with custom taxonomies (categories). I have a Custom Post Type called 'Portfolio' and it works as expected but a problem is with my hierarchical taxonomy that I have registered. I gave it a name: 'galleries'. Instead of displaying custom taxonomies it simply shows default categories from my blog. I found some similar problems on here but I realy don't know how to adopt other's solutions into my case. I am quite new to wordpress unfortunately. Can someone help me?

This is the code from my loop.php which is the template of my custom post type (this is my home page):

<div id="filtering-nav">
<a href="#" class="filter-btn"><span>Filter</span></a>
    <li><a href="#all" class="all">All</a></li>
    <?php $args=array('orderby' => 'name');
    foreach($galleries as $gallery){ ?>
    <li><a href="#<?php echo $gallery->gallery_nicename; ?>" class="<?php echo $gallery->gallery_nicename; ?>"><?php echo $gallery->name; ?></a></li>
    <?php } ?>
<div class="clearfix"></div>

Here is the code from my function.php:

add_action('init', 'portfolio_register');
function portfolio_register() {
     $labels = array(
        'name' => _x('My Portfolio', 'post type general name'),
        'singular_name' => _x('Portfolio Item', 'post type singular name'),
        'add_new' => _x('Add New', 'portfolio item'),
        'add_new_item' => __('Add New Portfolio Item'),
        'edit_item' => __('Edit Portfolio Item'),
        'new_item' => __('New Portfolio Item'),
        'view_item' => __('View Portfolio Item'),
        'search_items' => __('Search Portfolio'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/images/portfolio-icon.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','author','thumbnail','comments')
    register_post_type( 'portfolio' , $args );
// Custom taxonomy for Portfolio Categories (Galleries)
register_taxonomy('galleries', array('portfolio'), array('hierarchical' => true, 'label' => 'Galleries', 'singular_label' => 'Gallery', 'rewrite' => true, 'public' => true ));

Thanks in advance!

share|improve this question
<div id="filtering-nav">
<a href="#" class="filter-btn"><span>Filter</span></a>
    <li><a href="#all" class="all">All</a></li>
    <?php $args=array('orderby' => 'name','taxonomy'=>'galleries');
    foreach($galleries as $gallery){ ?>
    <li><a href="<?php echo get_category_link( $gallery->term_id ) ; ?>" class="<?php echo $gallery->gallery_nicename; ?>"><?php echo $gallery->name; ?></a></li>
    <?php } ?>
<div class="clearfix"></div>

When you pass argument to get_categories function , you need to pass name of taxonomy as taxonomy parameter to retrieve taxonomy instead of categories...

Here is complete reference..


Compare your code to below, you are missing taxonomies in args in register post type and rewrite slug in custom taxonomy arg. Below code is working perfectly.

$custom_slug = get_option('slug') != '' ? get_option('slug') : 'portfolio';

    $args = array(
        'labels'            => array(
            'name'                  => __('Portfolio'),
            'singular_name'         => __('Portfolio Project'),
            'add_new'               => __('Add Project'),
            'add_new_item'          => __('Add Project'),
            'new_item'              => __('Add Project'),
            'view_item'             => __('View Project'),
            'search_items'          => __('Search Portfolio'), 
            'edit_item'             => __('Edit Project'),
            'all_items'             => __('Complete Portfolio'),
            'not_found'             => __('No Projects found'),
            'not_found_in_trash'    => __('No Projects found in Trash')
        'taxonomies'        => array('portfolio-categories', 'portfolio-clients', 'portfolio-tags'),
        'public'            => true,
        'show_ui'           => true,
        '_builtin'          => false,
        '_edit_link'        => 'post.php?post=%d',
        'capability_type'   => 'post',
        'rewrite'           => array('slug' => __($custom_slug)),
        'hierarchical'      => false,
        'menu_position'     => 20,
        'menu_icon'         => WP_PLUGIN_URL . '/portfolio/images/icon.jpg',
        'supports'          => array('title', 'editor')

    /** create portfolio categories (taxonomy) */
    register_taxonomy('portfolio-categories', 'project', array(
            'hierarchical'      => true,
            'show_ui'           => true,
            'rewrite'           => array('slug' => __($custom_slug . '/category')),
            'labels'            => array(
                    'name'                          => __('Portfolio Categories'),
                    'singular_name'                 => __('Portfolio Category'),
                    'search_items'                  => __('Search Portfolio Categories'),
                    'popular_items'                 => __('Popular Portfolio Categories'),
                    'all_items'                     => __('All Portfolio Categories' ),
                    'parent_item'                   => __('Parent Portfolio Category'),
                    'parent_item_colon'             => __('Parent Portfolio Category'),
                    'edit_item'                     => __('Edit Portfolio Category'), 
                    'update_item'                   => __('Update Portfolio Category'),
                    'add_new_item'                  => __('Add New Portfolio Category'),
                    'new_item_name'                 => __('New Portfolio Category'),
                    'separate_items_with_commas'    => __('Separate Portfolio Categories with commas'),
                    'add_or_remove_items'           => __('Add or remove Portfolio Categories'),
                    'choose_from_most_used'         => __('Choose from the most used Portfolio Categories')

    /** create new custom post type */
    register_post_type('portfolio', $args);
share|improve this answer
Many thaks for your quick reply. Now it shows all custom taxonomies (categories) but the problem is that the filtering doesn't work yet. When I click on a particular category ie. 'Images' it shows all posts from all categories on a single page. – Adrian Jul 23 '11 at 15:44
I am trying to find some solution... – Adrian Jul 23 '11 at 16:08
@Adrian Can you post your code how you have created custom post type and custom taxonomy.. – Rajeev Vyas Jul 25 '11 at 6:37
Ok, it is above. – Adrian Jul 25 '11 at 21:26
@Adrian Have edited answer see above... – Rajeev Vyas Jul 26 '11 at 15:46

Your Answer


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.