2

I started playing with an idea a few days ago that will be using custom post types. I've never used CPTs before and am running into issues with the basic registration process.

The following registration code is hooked into init and I have verified that it is running, however I am not seeing "Slides" appear in the admin menu.

*EDIT: WP_DEBUG is enabled and nothing is being produced.*

register_post_type(self::$post_type, array(
    'labels'               => array(
        'name'               => __('Slides', 'bonestheme'),
        'singular_name'      => __('Slide', 'bonestheme'),
        'add_new_item'       => __('Add New Slide', 'bonestheme'),
        'edit_item'          => __('Edit Slide', 'bonestheme'),
        'new_item'           => __('New Slide', 'bonestheme'),
        'view_item'          => __('View Slide', 'bonestheme'),
        'search_items'       => __('Search Slides', 'bonestheme'),
        'not_found'          => __('No Slide Found', 'bonestheme'),
        'not_found_in_trash' => __('No slides found in Trash', 'bonestheme')
    ),
    'capability_type'      => array('slide', 'slides'),
    'description'          => 'Represents a single slide in the header slideshow.',
    'hierarchical'         => false,
    'menu_position'        => 5,
    'public'               => false,
    'register_meta_box_cb' => array('SlideJS', 'createCPTMetaboxes'),
    'rewrite'              => false,
    'show_in_admin_bar'    => false,
    'show_in_nav_menus'    => true,
    'show_ui'              => true,
    'supports'             => array('title', 'thumbnail')
    )
);

remove_post_type_support( self::$post_type, 'editor' );
  • At a guess, the public = false arg is hiding the CPT from the menu(you'll notice this was changed in the accepted answer). – t31os Feb 9 '14 at 20:47
  • It was changed in the accepted answer, but not in my code (which now works). Public sets the default value for a number of other values. All of the show_* values override this default value. See codex. – Dan Feb 9 '14 at 20:51
8

Remove

'capability_type'      => array('slide', 'slides'),

This works

add_action( 'init', 'slides_post_type' );
function slides_post_type() {

register_post_type( 'Slides',
    array(
'labels' => array(
    'name'               => __('Slides', 'bonestheme'),
    'singular_name'      => __('Slide', 'bonestheme'),
    'add_new_item'       => __('Add New Slide', 'bonestheme'),
    'edit_item'          => __('Edit Slide', 'bonestheme'),
    'new_item'           => __('New Slide', 'bonestheme'),
    'view_item'          => __('View Slide', 'bonestheme'),
    'search_items'       => __('Search Slides', 'bonestheme'),
    'not_found'          => __('No Slide Found', 'bonestheme'),
    'not_found_in_trash' => __('No slides found in Trash', 'bonestheme')
),

'description'          => 'Represents a single slide in the header slideshow.',
'hierarchical'         => false,
'menu_icon'            => 'dashicons-images-alt2',
'menu_position'        => 5,
'public'               => true,
'register_meta_box_cb' => array('SlideJS', 'createCPTMetaboxes'),
'rewrite'              => array( 'slug' => 'slides', 'with_front' => false ),
'show_in_admin_bar'    => false,
'show_in_nav_menus'    => true,
'show_ui'              => true,
'supports'             => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes')
));
}

enter image description here

  • It does indeed. Thanks! Any insight into why that was breaking things? Based on the Codex documentation, that syntax looks right to me... – Dan Feb 8 '14 at 20:36
  • Maybe its not a supported capability type. – Brad Dalton Feb 8 '14 at 20:44
  • @BradDalton Removing capability_type fixed the admin menu issue but now when I click on Add New page, it redirects me to home page, can you help me how to fix this? – Vikas Khunteta Sep 27 '17 at 12:29

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.