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'm having some custom post type but I want to add categories for it. Not for the URL(-structure) but for an archive page, which shows every category after each other. So the items are organized. Anyway to do this or isn't this possible?

share|improve this question
add comment

1 Answer 1

If you want to use builtin WordPress categories, while calling register_post_type function with taxonomies parameter set to category

If you want to create a custom category, then use register_taxonomy function to register a brand new taxonomy with second parameter to be your custom post type name and pass it taxonomy name to register_post_type as explained above.

A sample would look something like this

$args = array(
    'label' => __( 'Book' ),
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array( 'slug' => 'book' ),
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => null,
    'taxonomies' => array('language'),
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  ); 

  register_taxonomy(
        'language',
        'book',
        array(
            'label' => __( 'Language' ),
            'rewrite' => array( 'slug' => 'language' ),
            'hierarchical' => true,
        )
    );
  register_post_type( 'book', $args );
share|improve this answer
    
Anyway to get the category? $categories = get_categories($cat_args); just gets the normal post categories. –  Disgeae Jul 26 '13 at 10:55
    
Yes, get_terms( 'language', 'orderby=count&hide_empty=0' ); if you meant category by your custom taxonomy. –  M-R Jul 26 '13 at 11:00
    
And last one: posting the name? :) –  Disgeae Jul 26 '13 at 11:01
    
I dont get what you mean by "posting the name". p.s You should be searching a little bit before asking on SO. –  M-R Jul 26 '13 at 11:08
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.