I'm trying to get my head around CPT and Taxonomies. I've created a section on my WP site called Work and so I've got this in my functions.php file:

add_action('init', 'work_register');

function work_register() {

$labels = array(
    'name' => _x('Work', 'post type general name'),
    'singular_name' => _x('Work Item', 'post type singular name'),
    'add_new' => _x('Add New Work Item', 'portfolio item'),
    'add_new_item' => __('Add New Work Item'),
    'edit_item' => __('Edit Work Item'),
    'new_item' => __('New Work Item'),
    'view_item' => __('View Work Item'),
    'search_items' => __('Search Work'),
    '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,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','editor','thumbnail'),
    'taxonomies' => array('category', 'post_tag') // this is IMPORTANT

register_post_type('work' , $args );

register_taxonomy("work-categories", array("work"), array("hierarchical" => true, "label" => "Work Categories", "singular_label" => "Work Category", "rewrite" => true));

And I think I've got all of that right as I've got a section in my admin where I can add Work items. I wasn't sure whether to include this line:

'taxonomies' => array('category', 'post_tag') // this is IMPORTANT

because I want to create a new taxonomy called 'work categories' hence registering this at the end of my code using

register_taxonomy("work-categories", array("work"), array("hierarchical" => true, "label" => "Work Categories", "singular_label" => "Work Category", "rewrite" => true));

The admin screen displays a column for Categories and Tags, but not one for Work Categories - How do I ditch the columns for Categories and Tags and add a column for Work Categories??? What else do I need to add to my functions.php file to do this??

Also I want to know how I will be able to lists my Work Categories within my sidebar on my index-work.php and single-work.php pages.


I've added the following code to my index-work.php and single-work.php pages just before calling the sidebar:

$taxonomy = 'work-categories';
$queried_term = get_query_var($taxonomy);
$terms = get_terms($taxonomy, 'slug='.$queried_term);
if ($terms) {
echo '<ul>';
foreach($terms as $term) {
echo '<li><a href="'.get_term_link($term, $taxonomy).'">'.$term->name.'</a></li>';
echo '</ul>';

And this now outputs my Work Categories, but the links for these are /work-categories/artists/ for example which is fine, but they use the archive.php page - how can I get them to link to a page I've created? I've tried archive-artists.php but this isn't picked up. I don't want to use the blog archive.php page to display my work categories. Any ideas???

-----END EDIT-----



  • You should try to frame your questions on this site as actual questions, rather than a statement like this one. The process of converting the title to a question will help you define your issue into something more general as well as making it more interesting to people looking to write answers. – jerclarke Apr 19 '12 at 21:55

The page for 'work categories' appears as a sub-menu page of 'Work' CPT, after you've registered it correctly. These are very good posts to get started with CPTs: Thinkvitamin and Justin Tadlock. I always refer these when stuck with CPTs.

  • I've used both those site links to get where I am now but neither help to answer my query. I tried customising the code from ThinkVitamin to show columns in my admin panel for my Work Categories but it doesn't work. – Evie Milo Oct 17 '11 at 15:10
  • Ohh, sorry, I had scrolled a bit down so couldn't see it! – Rutwick Gangurde Oct 17 '11 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.