Search code examples
phpwordpresscustom-post-typetaxonomy

WP Custom Post Type Taxonomy - Need to create Categories


I am trying to create a custom post type called "Incentives". Within this custom post type, I would like to create a category titled "Lighting Incentives". I have created a function to register the custom post type and create the taxonomy/category. However, for some reason I am unable to register the taxonomy/category. The taxonomy/category does not appear in the WP dashboard. Also, the hierarchy of "Incentives" vs "Lighting Incentives" seems a bit mixed up. Here is my code

add_action('init', 'incentive_register');

function incentive_register() {

    $labels = array(
        'name' => _x('Lighting Incentives', 'post type general name'),
        'singular_name' => _x('Lighting Incentive', 'post type singular name'),
        'add_new' => _x('Add New', 'Lighting Incentive'),
        'add_new_item' => __('Add New Lighting Incentive'),
        'edit_item' => __('Edit Lighting Incentive'),
        'new_item' => __('New Lighting Incentive'),
        'view_item' => __('View Incentive'),
        'search_items' => __('Search Incentives'),
        '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() . '/article16.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => 'lighting-incentives',
        'menu_position' => null,
        'parent_item' => 'Incentives',
        'supports' => array('title','editor','thumbnail','excerpt','custom-fields','post-formats')
      ); 

    register_post_type( 'Incentive' , $args );
    register_taxonomy_for_object_type('category','Incentive');

        flush_rewrite_rules();
}

Solution

  • You should use lowercase for the name of your custom post type. Change this

    register_post_type( 'Incentive' , $args );
    register_taxonomy_for_object_type('category','Incentive');
    

    to this

    register_post_type( 'incentive' , $args );
    register_taxonomy_for_object_type('category','incentive');
    

    EDIT

    You should flush your permalinks only once