最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

metabox - meta box on custom post type

programmeradmin2浏览0评论

Okay I have look on the site and need more help! I am adding Learndash to my site and need a meta box to show on their custom post type pages.

Here is the meta box code I have which works fine for just normal posts;

    // META

$prefix = 'dbt_';
$meta_box = array(
    'id' => 'my-meta-box',
    'title' => 'Post Customization',
    'page' =>  'post', 
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
        array(
            'name' => 'Post Color',
            'id' => $prefix . 'color',
            'type' => 'select',
            'options' => array('orange', 'pink', 'green', 'purple')
        ),
        array(
            'name' => 'Image URL',
            'desc' => 'Optional',
            'id' => $prefix . 'img-url',
            'type' => 'text',
            'std'  => 'Image'
        ),
        array(
            'name' => 'Video URL',
            'desc' => 'Optional',
            'id' => $prefix . 'video-url',
            'type' => 'text',
            'std'  => 'Video'
        ),
        array(
            'name' => 'Link URL',
            'desc' => 'Optional',
            'id' => $prefix . 'link-url',
            'type' => 'text',
            'std'  => 'Link'
        ),
     )
);

add_action('admin_menu', 'mytheme_add_box');

Now how do I get it to show on all the following post types;

sfwd-courses sfwd-lessons sfwd-topics ...

Replacing 'page' => 'post', with 'page' => 'sfwd-courses', shows the meta box on the courses page but not normal posts.

I thought the following should work but does not...

'page' => 'post', 'sfwd-courses', 'sfwd-lessons', 'sfwd-topics',

Please help...

Okay I have look on the site and need more help! I am adding Learndash to my site and need a meta box to show on their custom post type pages.

Here is the meta box code I have which works fine for just normal posts;

    // META

$prefix = 'dbt_';
$meta_box = array(
    'id' => 'my-meta-box',
    'title' => 'Post Customization',
    'page' =>  'post', 
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
        array(
            'name' => 'Post Color',
            'id' => $prefix . 'color',
            'type' => 'select',
            'options' => array('orange', 'pink', 'green', 'purple')
        ),
        array(
            'name' => 'Image URL',
            'desc' => 'Optional',
            'id' => $prefix . 'img-url',
            'type' => 'text',
            'std'  => 'Image'
        ),
        array(
            'name' => 'Video URL',
            'desc' => 'Optional',
            'id' => $prefix . 'video-url',
            'type' => 'text',
            'std'  => 'Video'
        ),
        array(
            'name' => 'Link URL',
            'desc' => 'Optional',
            'id' => $prefix . 'link-url',
            'type' => 'text',
            'std'  => 'Link'
        ),
     )
);

add_action('admin_menu', 'mytheme_add_box');

Now how do I get it to show on all the following post types;

sfwd-courses sfwd-lessons sfwd-topics ...

Replacing 'page' => 'post', with 'page' => 'sfwd-courses', shows the meta box on the courses page but not normal posts.

I thought the following should work but does not...

'page' => 'post', 'sfwd-courses', 'sfwd-lessons', 'sfwd-topics',

Please help...

Share Improve this question asked Apr 17, 2014 at 18:21 aled2305aled2305 176 bronze badges 1
  • This isn't default WordPress meta box code... it looks like it is supposed to use the Meta Box plugin? – helgatheviking Commented Apr 17, 2014 at 19:24
Add a comment  | 

1 Answer 1

Reset to default 0

You will need to add your post types in an array. So your code should look like this

'pages' => array('post', 'sfwd-courses', 'sfwd-lessons', 'sfwd-topics'),

You should also have a look at this tutorial that I find helpful as well

发布评论

评论列表(0)

  1. 暂无评论