Support » Plugins » Hacks » Attachment Custom Post Types

  • Resolved olyma


    Hi, I’m trying to create a custom post type that behaves as or has the capability of an attachment. Essentially, I have a bunch of images that I’d like to store as their own custom post type that is separate from the box standard Media Library, but will behave the same as a Media Library. For organizational purposes, I need to have a second media library in the admin.

    The problem I’ve been having is, though I’ve created custom post types that are “posts” before, I’ve never created a custom post type that is an “attachment.” Below is the code I have thus far:

    function create_planting() {
    	register_post_type( 'planting',
    			'labels' => array(
    				'name' => __( 'Plantings' ),
    				'singular_name' => __( 'Planting' )
    		'public' => true,
    		'_builtin' => false,
    		'capability_type' => 'attachment',
    		'has_archive' => false,
    		'show_ui' => true,
    		'menu_position' => 25
    add_action( 'init', 'create_planting' );

    With the code above, the CPT refuses to show up in the admin menu, but if I eliminate the line: “'capability_type' => 'attachment',” OR if I switch out the word “attachment” and replace it with “post” in that same line, in both cases it will suddenly show up in the admin menu, but as if it were for posts instead of attachments.

    How do I get this to appear and behave as an attachment?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    You can view the settings used to register all post types with


    You will see (view source, not browser output) not even attachments use attachment capabilities, post is used. I would think if your arguments match the settings here exactly, except in name, you should get what you desire.

    Thank you, the print_r code you gave me is extremely insightful, and helpful — I know I’ll use a chunk of it to get this working. I still don’t have it completely working yet, but I’ll post back here a bit later on my progress and if I have any further questions. Thank you again!

    Just checking back in with an update, in case anyone else might be engaging with this issue too. I tried a bunch of things to try to get it to work, but couldn’t seem to.

    In the end, I’ve just let the out-of-the-box Media attachment section that comes with WordPress remain as is as THE thing that deals with all the images for the site I’m working on — and then I’ve created a custom taxonomy and used a plugin to attach images to the taxonomy. This way I can just select from that taxonomy array, the images to associate with a post. It’s a bit of a different solution that I expected, but it’s working out.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Attachment Custom Post Types’ is closed to new replies.