• I’ve found a few examples of how to create custom post types but I’ve not managed to get them to work e.g from here

    https://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress

    The problem is capability_type. If I comment it out everything works; if I leave it there the labels disappear.

    What on earth am I doing wrong? I’ve stripped the code down to the bare minimum.

    add_action( 'init', 'create_my_post_types' );
    
    function create_my_post_types() {
    	register_post_type( 'super_duper',
    		array(
    			'labels' => array(
    				'name' => __( 'Super Dupers' ),
    				'singular_name' => __( 'Super Duper' )
    			),
    			'public' => true,
    	'capability_type' => 'super_duper',
    
    		)
    	);
    }
Viewing 15 replies - 1 through 15 (of 46 total)
  • Aimee

    (@greatdanemaniac)

    I think that capability type could only be “post” or “page”, but I’m not sure. I hope you figure it out.

    https://codex.www.ads-software.com/Function_Reference/register_post_type
    https://codex.www.ads-software.com/Function_Reference/register_post_type#Arguments

    capability_type
    (string) (optional) The post type to use for checking read, edit, and delete capabilities.
    Default: “post”

    I imagine that you cannot use the post type you’re registering as the post type with which to look at for capabilities (as you’re just registering it at that point), try post, page or another post type.

    I agree with greatdanemaniac.

    Thread Starter richarduk

    (@richarduk)

    Thanks for your replies.

    I have snippets of code from all over the internet but I’ve still not managed to make it work.

    The whole point of the custom post type capabilities is that we can change them. After that, it should be possible to assign them to a new role.

    This would mean that we could end up with a role of ‘Designer’ who can only edit ‘Graphics’ posts and not ordinary posts or Pages, say.

    I’ve been going round in circles. Am I doing something wrong, or is just that few people are trying to do this yet?

    Of course, capability control means nothing without being able to choose who has the capabilities. That’s what my Members plugin was created for. It’s ideal for this scenario.

    that’s from teh tutorial you linked. I thhink you need to set up the role super_duper in WP, otherwise, you are making the capabilities for the post super_duper, but you have no super_duper, so nobody is allowed to edit the post. You have to choose who has the capabilities to edit the new post type….. (I think….I’m just kind of guessing after reading the tutorial)

    That relates to my next question.

    How are you registering the role and/or capabilities and can i see the code you’re using to do so?

    NOTE: Maybe you might consder using a plugin to register the roles/caps just to see if behaviour works any differently.

    https://www.ads-software.com/extend/plugins/members/ – would be my suggestion, best role plugin i’ve used to date.

    Thread Starter richarduk

    (@richarduk)

    Oh yes yes yes.
    Many times, in many ways.

    Sorry to sound frustrated.

    Here’s a link to related? problems? https://core.trac.www.ads-software.com/ticket/14122

    Here’s my code. It’s a complete jumble, because I try things out, comment them out when they don’t work, borrow bits that I think might work, start a new page with the bits I do know work etc.

    So this is a conglomeration of three pages of code. More of a pointer to some of the things I’ve been trying.

    *code moderated*
    Replaced with pastebin.
    https://wordpress.pastebin.com/ftH7RjMm

    Thread Starter richarduk

    (@richarduk)

    Sorry, thought I’d lost my post

    Sorry had to moderate your code(another mod already removed the post), please don’t post huge portions of code (lots of scrolling for those of us on small screens – we usually moderate any code over 15-20 lines).

    Back to the topic at hand though, have you seen my suggestion above regarding using a role plugin?

    Thread Starter richarduk

    (@richarduk)

    Hmmm. I have an inherent aversion to plugins when code will do the trick, because with a plugin I’m dependent on the plugin author for the functioning of my site. So plugins for me are only for non-critical functions.

    That said, the developer at the site I linked to in my first post has a role plugin. I’ve already tried to figure it out once, but I can have another look and see if there’s anything obvious that I’m missing.

    Yes, Members is Justin’s plugin, same guy.. ??

    I can install it if you have problems understanding how to use it..

    Thread Starter richarduk

    (@richarduk)

    Thanks:)

    I meant figuring out the code.

    If you can clarify what you need help understanding i’ll do what i can to help.. ??

    Plugin suggestion was simply to take the cap/role creation out of the equation, i’ve used the plugin, i know it works, and that’s one thing we could eliminate as a possible cause (almost, can’t ever be 100% sure), but if it doesn’t make a lick of difference to your code not working then obviously we can drop that idea… and move onto looking back at the register_post_type code.

    Just trying to narrow down exactly which area is the problem, i currently suspect it’s with the role/cap creation as RVoodoo suggested above also. I could be wrong, and if i am i’ll go back over the other code with you, but for now i’d ask that you try the plugin route to save me having to test code that i’m not familiar with, although i’m happy to do that if the need arises (time permitting).

    Thread Starter richarduk

    (@richarduk)

    Thanks, t31os_, that’s a really generous offer. I’m going to start with a clean site, instal the plugin, then report back ??

    Thread Starter richarduk

    (@richarduk)

    Ok …

    Completely clean instal (well, oldish site, but I haven’t messed around with roles and capabilities on it.) Minimal plugins.

    Installed the ‘Members’ plugin noted above. Acitvated Edit roles, new roles, content permissions.

    Made sure Administrator had every single role possible, including edit_roles.

    Everything fine.

    Added this to functions.php (bare bones code)

    add_action( 'init', 'create_my_post_types' );
    
    function create_my_post_types() {
    	register_post_type( 'super_duper',
    		array(
    			'labels' => array(
    				'name' => __( 'Super Dupers' ),
    				'singular_name' => __( 'Super Duper' )
    			),
    			'public' => true,
    	//'capability_type' => 'super_duper',
    
    		)
    	);
    }

    ‘Super Duper’ post type appeared in Admin sidebar.

    Uncommented 'capability_type' => 'super_duper', from functions.php and ‘Super Duper’ disappeared from sidebar.

    Haven’t proceeded any further i.e. adding a new role in functions.php or from the Admin screen.

    I’ll recreate your steps on my install and let you know how i get on, bear with me a little while, i’m just making a few quick responses to other threads then i’ll take a crack it.

Viewing 15 replies - 1 through 15 (of 46 total)
  • The topic ‘Anyone managed to get custom post types capabilities working?’ is closed to new replies.