Reputation: 1567
I just created a custom post type, but for some reason the Featured Image meta box isn't showing up.
It does show on the "posts" post type though.
I have enabled theme support for thumbnails and have added the following code in my custom post type code.
<?php
function register_cpt_product() {
$labels = array(
'name' => _x( 'Products', 'product' ),
'singular_name' => _x( 'Product', 'product' ),
'add_new' => _x( 'Add New', 'product' ),
'add_new_item' => _x( 'Add New Product', 'product' ),
'edit_item' => _x( 'Edit Product', 'product' ),
'new_item' => _x( 'New Product', 'product' ),
'view_item' => _x( 'View Product', 'product' ),
'search_items' => _x( 'Search Products', 'product' ),
'not_found' => _x( 'No products found', 'product' ),
'not_found_in_trash' => _x( 'No products found in Trash', 'product' ),
'parent_item_colon' => _x( 'Parent Product:', 'product' ),
'menu_name' => _x( 'Products', 'product' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Allows the user to create products',
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post'
);
register_post_type( 'product', $args );
}
add_action( 'init', 'register_cpt_product' );
?>
The weird thing is, that on the pages which lists my entries for my post type, there is a column called Thumbnail.
Anyone know what is going on?
Thanks
Upvotes: 15
Views: 38941
Reputation: 1983
While this is an old question, it has been asked many more times. I was having this same problem with no fixes -- until I realized, that the user must also have the capability to upload images. If you are using a custom role (or logged in as contributor or subscriber) your role (or user) must have the capability of upload_files
.
Upvotes: 0
Reputation: 3717
Thumbnails are by default disabled, the WordPress Codex explicitly states so here,
Themes have to declare their support for post thumbnails before the interface for assigning these images will appear on the Edit Post and Edit Page screens.
Make sure you have also done add_theme_support('post-thumbnails')
somewhere in your theme/plugin, or that your post type is in the list of post types supplied to the above function (second argument is an optional array of post types) if you are already enabling it per post type.
It appears the "Screen options" setting for Featured post can be set to hide/show per post type. Though it's far fetched it might have been deactivated, though it should be activated by default I guess. Also try checking the return value of post_type_supports('project', 'thumbnail')
to determine if the setting is actually set as intended, which would point to the issue being related to the admin section only.
The featured post meta box is added to the admin section by the follow lines of code:
if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) )
add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low');
Perhaps you could run that if-statement in your theme/plugin and make sure it returns true as intended. In case it is, you might also want to inspect the edit page's source to see if #postimagediv
is in the markup but not displaying.
UPDATE:
I just pasted the following code in at the end of functions.php
of the Twenty Eleven theme, on a WordPress 3.4.2 install with no plugins activated, and it worked fine - the type showed up and I was able to see the post thumbnail meta box in the edit screen.
add_theme_support('post-thumbnails');
function setup_types() {
register_post_type('mytype', array(
'label' => __('My type'),
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'show_ui' => true,
));
}
add_action('init', 'setup_types');
Upvotes: 29
Reputation: 1926
I realize this is an older question, but none of these solutions worked for me. It turned out there were two problems, first: multiple plugins trying to call add_theme_support
. The second was that they assumed certain types, or needed knowledge of the theme when adding support.
In the following code snippet I am safely first determining what the theme support is, and then adding my custom type to the list. By doing this in your plugin it will be compatible with other friendly themes or plugins. In fact I think a safe_add_theme_support
would be nice. Anyway, I hope this helps someone and saves them from a frustrating evening.
$currentPostThumbnails = get_theme_support('post-thumbnails');
if(is_array($currentPostThumbnails)) {
add_theme_support( 'post-thumbnails', array_merge($currentPostThumbnails, array( 'mytype' )) );
}else{
add_theme_support( 'post-thumbnails', 'mytype');
}
Upvotes: 2
Reputation: 294
i've got same problem. i used "custom post type ui" plugin for creating a 'portfolio' post type. i tried lot of things, but didn't work. Finally i've tried this code
add_action('init', 'my_custom_init');
function my_custom_init() {
// 'portfolio' is my post type, you replace it with yours
add_post_type_support( 'portfolio', 'thumbnail' );
}
it worked !! i've got this code from codex!!
Upvotes: 4
Reputation: 108
I've run into this problem a couple of times. I disabled the BackupBuddy plugin and the Featured Image meta box came back. May not work in your instance, but hopefully this helps someone else.
May want to try disabling all your plugins and turning them back on to see if one by one to see if it is a problem with a plugin.
Upvotes: 0
Reputation: 21
If you're running a custom theme, that theme may have a theme_support call somewhere in its custom files that might be overriding your theme support call.
If You can track down that track down that theme's call, you can copy it to your own theme file and then add your custom post type to it.
You can put it inside a function and then use an action hook, like after_setup_theme.
here's an example of a custom theme original support call:
add_theme_support('post-thumbnails', array('slide-items','post','gallery-items','audio-items','video-items','page','event-items',
I was running a child theme off that main theme and needed a custom post type called 'staff'. Even though i declared support for that custom post type to include thumbnails, the featured image meta box wasn't showing.
I added the following code to my child theme functions.php file. Notice, I added 'staff' at the end of the function.
add_action( 'after_setup_theme', 'add_theme_support' );
function add_theme_support (){
add_theme_support('post-thumbnails', array('slide-items','post','gallery-items','audio-items','video-items','page','event-items','staff'));
}
Hope that helps.
Upvotes: 2
Reputation: 1567
Well I seem to have solved the problem. I was running 3.4.2, so I deleted all the wordpress installation files (except wp-config.php and my themes), and then used the upgrade feature to get to 3.4.2 again. On 3.4.1 it works, but on 3.4.2 it doesn't.
I have downgraded again, and will wait for a future update. All I can say is this is one weird bug.
Thanks for you help guys.
Upvotes: -1
Reputation: 2878
Make sure you have Featured Image set to Show on Screen in the Screen Options on the Post Editor page
Upvotes: 0