Wordpress add_meta_box在类中不工作时的自定义帖子类型
问题描述:
我有一个问题,将元框放入用插件创建的自定义帖子类型中。Wordpress add_meta_box在类中不工作时的自定义帖子类型
我已经经历了上百次的代码,开始怀疑类是否会产生影响,请问array($this, 'insT_tag')
作为回调参考吗?
我真的不明白什么是错的!我有一个我用来创建类型的代码的示例,然后添加元框。有没有人有任何想法?
function init_custom_post_types() {
register_post_type('inGallery', array(
'labels' => array(
'name' => __('inGalleries', 'inGallery'),
'singular_name' => 'inGallery',
'add_new' => 'Add new inGallery',
'add_new_item' => 'Add new inGallery',
'edit_item' => 'Edit inGallery',
'new_item' => 'New inGallery',
'view_item' => 'Show inGallery',
'search_items' => 'Search inGallery',
'not_found' => 'Not found',
'not_found_in_trash' => 'No inGallery was found in trash',
'parent_item_colon' => 'Parent:'
),
'public' => true,
'exclude_from_search' => false,
'query_var' => true,
'capability_type' => 'post',
'show_in_nav_menus' => true,
'menu_position' => 5,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions'),
'taxonomies' => array('category', 'post_tag'),
'rewrite' => array('slug' => 'in', 'with_front' => false),
'publicly_queryable' => true,
'exclude_from_search' => false,
'can_export' => true,
'register_meta_box_cb' => array($this , 'add_inGallery_metaboxes')
));
// Add the custom type to the homepage post loop
add_filter('pre_get_posts', array($this, 'customTypeToPosts'));
}
public function add_inGallery_metaboxes() {
add_meta_box('insT_tag', 'Hash Tag', array($this, 'insT_tag'), 'inGallery', 'side', 'high' , array('tester'));
}
public function insT_tag ($a) {
print_r($a);
echo'<input type="text" value="tester"/>';
}
答
这么多小时后我已经找到了答案......这是可怕的简单。看来帖子类型名称被转换为小写,所以我的camelCase名称inGallery
成为ingallery
。那简单!
另外值得注意的调试一个很好的方法是运行像:
foreach ($post_types as $post_type) {
echo "<p>" . $post_type . '</p>';
}
所以,你可以看到引用叫什么。