在wp-admin中,我創建了一個新的管理菜單頁面。Wordpress設置自定義文章類型的特色圖像
add_menu_page('My custom post page type title', 'My custom post type menu', '', 'my-custom-slug', '', '', 99);
add_submenu_page('my-custom-slug', 'Add new', 'Add new', 'manage_options', 'post-new.php?post_type=my-custom-post-type', '');
我想使用像post-new.php和edit.php這樣的面板,所以我註冊了一個自定義的帖子類型。
register_post_type('my-custom-post-type',
array('labels'=>array('name'=>__('Products','text-domain'),
'singular_name'=>__('Product','text-domain'),
'menu_name'=>_x('Products','Admin menu name','text-domain'),
'add_new'=>__('Add Product','text-domain'),
'add_new_item'=>__('Add New Product','text-domain'),
'edit_item'=>__('Edit Product','text-domain'),
'new_item'=>__('New Product','text-domain'),
'view_item'=>__('View Product','text-domain'),
'not_found'=>__('No Products found','text-domain'),
'not_found_in_trash'=>__('No Products found in trash','text-domain')),
'supports'=>array('title','editor','thumbnail','comments')
'rewrite'=>array('slug'=>'mscases'),
'public'=>true,
'capability_type'=>'post'));
自定義菜單頁能正常工作,而元框Featured Image
也工作得很好,我可以選擇圖像中的媒體庫。
當我選擇圖片後,它不會出現在精選圖片元框中,並且admin-ajax.php
響應是-1(我檢查帖子頁面,如果成功,則爲零)。
但是,如果我將參數my-custom-post-type
更改爲product
(如woocommerce),則會顯示我選取的精選圖像。
有沒有什麼我想念編碼?