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 trouble seeing why categories are not appearing for Knowledge Base and Articles. What's wrong with this code?

<?php
// Custom post types

/* faq */
add_action( 'init', 'faq_post_type' );
if ( ! function_exists( 'faq_post_type' ) ) {
function faq_post_type() {

    //Register FAQ Post Type
    register_post_type( 'faq',
        array(
        'description' => __( 'FAQ Articles', 'guerilla' ),
        'labels' => array(
                'name' => __( 'FAQ', 'guerilla' ),
                'singular_name' => __( 'FAQ', 'guerilla' ),
                'add_new' => __('Add New', 'guerilla'),  
                'add_new_item' => __('Add New FAQ', 'guerilla'),  
                'edit_item' => __('Edit FAQ', 'guerilla'),  
                'new_item' => __('New FAQ', 'guerilla'),  
                'view_item' => __('View FAQ', 'guerilla'),  
                'search_items' => __('Search FAQ', 'guerilla'),  
                'not_found' =>  __('No FAQ found', 'guerilla'),  
                'not_found_in_trash' => __('No FAQ found in Trash', 'guerilla')
            ),
        'public' => true,
        'menu_position' => 7,
        'rewrite' => array('slug' => 'faq'),
        'supports' => array(
            'title',
            'editor'),
        'public' => true,
        'show_ui' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false
        )
    );
}
}

function faq_taxonomy()
{
    $labels = array('name' => __( 'Categories', 'guerilla' ),
                    'singular_name' => __( 'Category', 'guerilla' ),
                    'search_items' =>  __( 'Search Categories', 'guerilla' ),
                    'all_items' => __( 'All Categories', 'guerilla' ),
                    'parent_item' => __( 'Parent Category', 'guerilla' ),
                    'parent_item_colon' => __( 'Parent Category:', 'guerilla' ),
                    'edit_item' => __( 'Edit Category', 'guerilla' ),
                    'update_item' => __( 'Update Category', 'guerilla' ),
                    'add_new_item' => __( 'Add New Category', 'guerilla' ),
                    'new_item_name' => __( 'New Category Name', 'guerilla' ),
                    'menu_name' => __( 'Categories', 'guerilla' ) );

    register_taxonomy(  'faq_category',
                        array( 'faq' ),
                        array( 'hierarchical' => true,
                        'labels' => $labels,
                        'show_ui' => true,
                        'public' => true,
                        'query_var' => true,
                        'rewrite' => array( 'slug' => 'faq_category' )));
}

add_action( 'init', 'faq_taxonomy' );

/* Knowledgebase*/
add_action( 'init', 'KnowledgeBase_post_type' );
if ( ! function_exists( 'KnowledgeBase_post_type' ) ) {
function KnowledgeBase_post_type() {


    register_post_type( 'KnowledgeBase',
        array(
        'description' => __( 'KnowledgeBase Articles', 'guerilla' ),
        'labels' => array(
                'name' => __( 'KnowledgeBase', 'guerilla' ),
                'singular_name' => __( 'KnowledgeBase', 'guerilla' ),
                'add_new' => __('Add New', 'guerilla'),  
                'add_new_item' => __('Add New KnowledgeBase Articles', 'guerilla'),  
                'edit_item' => __('Edit KnowledgeBase Articles', 'guerilla'),  
                'new_item' => __('New KnowledgeBase Articles', 'guerilla'),  
                'view_item' => __('View KnowledgeBase Articles', 'guerilla'),  
                'search_items' => __('Search KnowledgeBase Articles', 'guerilla'),  
                'not_found' =>  __('No KnowledgeBase Articles found', 'guerilla'),  
                'not_found_in_trash' => __('No KnowledgeBase Articles found in Trash', 'guerilla')
            ),
        'public' => true,
        'menu_position' => 5,
        'rewrite' => array('slug' => 'KnowledgeBase'),
        'supports' => array(
            'title',
            'editor'),
        'public' => true,
        'show_ui' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false
        )
    );
}
}

function KnowledgeBase_taxonomy()
{
    $labels = array('name' => __( 'Categories', 'guerilla' ),
                    'singular_name' => __( 'Category', 'guerilla' ),
                    'search_items' =>  __( 'Search Categories', 'guerilla' ),
                    'all_items' => __( 'All Categories', 'guerilla' ),
                    'parent_item' => __( 'Parent Category', 'guerilla' ),
                    'parent_item_colon' => __( 'Parent Category:', 'guerilla' ),
                    'edit_item' => __( 'Edit Category', 'guerilla' ),
                    'update_item' => __( 'Update Category', 'guerilla' ),
                    'add_new_item' => __( 'Add New Category', 'guerilla' ),
                    'new_item_name' => __( 'New Category Name', 'guerilla' ),
                    'menu_name' => __( 'Categories', 'guerilla' ) );

    register_taxonomy(  'KnowledgeBase_category',
                        array( 'KnowledgeBase' ),
                        array( 'hierarchical' => true,
                        'labels' => $labels,
                        'show_ui' => true,
                        'public' => true,
                        'query_var' => true,
                        'rewrite' => array( 'slug' => 'KnowledgeBase_category' )));
}

add_action( 'init', 'KnowledgeBase_taxonomy' );

/* Articles */
add_action( 'init', 'Articles_post_type' );
if ( ! function_exists( 'Articles_post_type' ) ) {
function Articles_post_type() {

    //Register FAQ Post Type
    register_post_type( 'Articles',
        array(
        'description' => __( 'Articles', 'guerilla' ),
        'labels' => array(
                'name' => __( 'Articles', 'guerilla' ),
                'singular_name' => __( 'Articles', 'guerilla' ),
                'add_new' => __('Add New', 'guerilla'),  
                'add_new_item' => __('Add New Articles', 'guerilla'),  
                'edit_item' => __('Edit Articles', 'guerilla'),  
                'new_item' => __('New Articles', 'guerilla'),  
                'view_item' => __('View Articles', 'guerilla'),  
                'search_items' => __('Search Articles', 'guerilla'),  
                'not_found' =>  __('No Articles found', 'guerilla'),  
                'not_found_in_trash' => __('No Articles found in Trash', 'guerilla')
            ),
        'public' => true,
        'menu_position' => 6,
        'rewrite' => array('slug' => 'Articles'),
        'supports' => array(
            'title',
            'editor'),
        'public' => true,
        'show_ui' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false
        )
    );
}
}

function Articles_taxonomy()
{
    $labels = array('name' => __( 'Categories', 'guerilla' ),
                    'singular_name' => __( 'Category', 'guerilla' ),
                    'search_items' =>  __( 'Search Categories', 'guerilla' ),
                    'all_items' => __( 'All Categories', 'guerilla' ),
                    'parent_item' => __( 'Parent Category', 'guerilla' ),
                    'parent_item_colon' => __( 'Parent Category:', 'guerilla' ),
                    'edit_item' => __( 'Edit Category', 'guerilla' ),
                    'update_item' => __( 'Update Category', 'guerilla' ),
                    'add_new_item' => __( 'Add New Category', 'guerilla' ),
                    'new_item_name' => __( 'New Category Name', 'guerilla' ),
                    'menu_name' => __( 'Categories', 'guerilla' ) );

    register_taxonomy(  'Article_category',
                        array( 'Articles' ),
                        array( 'hierarchical' => true,
                        'labels' => $labels,
                        'show_ui' => true,
                        'public' => true,
                        'query_var' => true,
                        'rewrite' => array( 'slug' => 'Article_category' )));
}

add_action( 'init', 'Articles_taxonomy' );
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Your Knowledgebase and Articles CPT slugs are capitalized. This is not allowed - see the codex.

(string) (required) Post type. (max. 20 characters, can not contain capital letters or spaces)

Change these to all lower case, both in the first parameter of the register_post_type and in the second parameter of the register_taxonomy, and you should be good to go.

share|improve this answer
    
FAQ is not linked yet i can see the categories for FAQ. –  user31891 May 3 '13 at 19:04
    
I've tried the suggested idea and that dont work. –  user31891 May 3 '13 at 19:09
    
I've totally revised my answer. –  vancoder May 3 '13 at 19:26
    
Thanks! Your a star –  user31891 May 3 '13 at 20:00
    
If my answer is correct please click the tick next to it, so that other people with the same issue can see it is correct. –  vancoder May 3 '13 at 20:50
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.