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 just built up a beta environment for testing my new Wordpress site. I didn't migrate the database; I did my own installation again and ported over my theme (it's a simple theme) to my new instance. Everything is working great, except for the one custom post type that I am using.

Here is the relevant code from functions.php:

function createCommunityPostType() {
    $args = array(
            'public' => true,
            'label' => 'Community',
            'capability_type' => 'community',
                'capabilities' => array(
                                'edit_post' => 'edit_community',
                                'edit_private_posts' => 'edit_private_communities',
                                'edit_published_posts' => 'edit_published_communities',
                                'edit_posts' => 'edit_communities',
                                'edit_others_posts' => 'edit_others_communities',

                                'delete_post' => 'delete_community',
                                'delete_posts' => 'delete_communities',
                                'delete_others_posts' => 'delete_others_communities',
                                'delete_private_posts' => 'delete_private_communities',
                                'delete_published_posts' => 'delete_published_communities',

                                'read_private_posts' => 'read_private_communities',
                                'read_post' => 'read_community',
                                'publish_posts' => 'publish_communities'
                ),
                'map_meta_cap' => true,
                'has_archive' => true
    );
    register_post_type('community', $args );
}
add_action('init', 'createCommunityPostType');

My custom post type isn't showing up in the menu and I can see that the capabilities don't exist (I'm using the members plugin to make that more visible).

I know the code is executing because I added some simple print statements before and after the call to register_post_type. The print statements were part of the HTML response.

I can't figure out why this post type isn't working. I have other methods in functions.php to handle stylesheets, scripts, some overrides for menus and sidebars and so on. Those are all working fine.

Edit:

I changed to use default capabilities and the menu option is still not appearing:

function createCommunityPostType() {
    $args = array(
            'public' => true,
            'label' => 'Community',
            'capability_type' => 'community',
                'capabilities' => array(
                                'edit_post' => 'edit_posts',
                                'edit_private_posts' => 'edit_posts',
                                'edit_published_posts' => 'edit_posts',
                                'edit_posts' => 'edit_posts',
                                'edit_others_posts' => 'edit_posts',

                                'delete_post' => 'delete_posts',
                                'delete_posts' => 'delete_posts',
                                'delete_others_posts' => 'delete_posts',
                                'delete_private_posts' => 'delete_posts',
                                'delete_published_posts' => 'delete_posts',

                                'read_private_posts' => 'read',
                                'read_post' => 'read',
                                'publish_posts' => 'publish_posts'
                ),
            'map_meta_cap' => true,
                'has_archive' => true
    );
    register_post_type('community', $args );
}
add_action('init', 'createCommunityPostType');

I did however switch to using some very basic sample code from Wordpress and that Custom Post Type (CPT) appears:

function codex_custom_init() {
    $args = array( 'public' => true, 'label' => 'Books' );
    register_post_type( 'book', $args );
}
add_action( 'init', 'codex_custom_init' );
share|improve this question
    
What Plugins do you have active? To eliminate possible issues with the Members Plugin, can you change the capabilities to reference core-defined capabilities, and report whether or not the CPT appears in the admin menu? –  Chip Bennett Apr 25 '13 at 14:43
    
@ChipBennett - I am only using three plugins: Members, TinyMCE and WP LESS. All three are enabled. I updated my original post with the results of switching to default capabilities. –  Ek0nomik Apr 25 '13 at 15:00
    
I think it might be a good idea to check what the register_post_type() function returns: $register_cpt_return = register_post_type('community', $args ); if( is_wp_error( $register_cpt_return ) ) wp_die( $register_cpt_return ); } Could you run this code and report the message you get? –  Fränk Apr 25 '13 at 15:00
    
I am not seeing any error message after adding this code to my method. –  Ek0nomik Apr 25 '13 at 15:24
    
I would slowly build from a simple call to the more complex call, eliminating by process of elimination where the error lies. –  GhostToast Apr 25 '13 at 15:33
show 1 more comment

1 Answer

up vote 3 down vote accepted

One problem is that your 'capability_type' parameter 'community' doesn't match your 'capabilities' array values.

From the Codex:

capability_type

(string or array) (optional) The string to use to build the read, edit, and delete capabilities. May be passed as an array to allow for alternative plurals when using this argument as a base to construct the capabilities, e.g. array('story', 'stories'). By default the capability_type is used as a base to construct capabilities. It seems that map_meta_cap needs to be set to true, to make this work.

Your capability type is:

'capability_type' => 'community'

And note your 'capabilities' array:

'capabilities' => array(
    'edit_post' => 'edit_community',
    'edit_private_posts' => 'edit_private_communities',
    'edit_published_posts' => 'edit_published_communities',
    'edit_posts' => 'edit_communities',
    'edit_others_posts' => 'edit_others_communities',

    'delete_post' => 'delete_community',
    'delete_posts' => 'delete_communities',
    'delete_others_posts' => 'delete_others_communities',
    'delete_private_posts' => 'delete_private_communities',
    'delete_published_posts' => 'delete_published_communities',

    'read_private_posts' => 'read_private_communities',
    'read_post' => 'read_community',
    'publish_posts' => 'publish_communities'
),

Your capability type is singular, and your constructed capabilities are plural.

Try changing capability type to this:

'capability_type' => array( 'community', 'communities' )

Also, if you define 'capability_type', you do not need to define each capability explicitly. So, try omitting the 'capabilities' argument entirely.

If your CPT doesn't appear after that, then the issue is likely due to your Members Plugin configuration:

  1. Ensure you have properly defined your custom capabilities
  2. Ensure that the current user has the capabilities referenced in the CPT.
share|improve this answer
    
Thanks for your help Chip. I am still new to the Wordpress world and I forgot that the capabilities aren't automatically generated by Wordpress when setting up a CPT. I needed to go in and create those capabilities. Thanks! –  Ek0nomik Apr 25 '13 at 17:54
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.