我跟着this tutorial 关于如何在我制作的自定义帖子类型上创建元盒,当时它工作得很好。第一次很有魅力。但这次,在一个非常相似的环境中,情况并非如此。有趣的是,我可以在管理页面中看到显示或隐藏元数据库的选项。还有,如果我搞砸了add_meta_box
位,它会在元框中添加一个PHP错误表,否则就会丢失。
这是我函数中的当前代码。php:
// Custom post type arcticles
function create_arcticles()
{
register_taxonomy_for_object_type(\'category\', \'arcticles\'); // Register Taxonomies for Category
register_taxonomy_for_object_type(\'post_tag\', \'arcticles\');
register_post_type(\'arcticles\', // Register Custom Post Type
array(
\'labels\' => array(
\'name\' => __(\'arcticles\', \'arcticles\'), // Rename these to suit
\'singular_name\' => __(\'arcticle\', \'arcticles\'),
\'add_new\' => __(\'Adicionar novo\', \'arcticles\'),
\'add_new_item\' => __(\'Adicionar novo arcticle\', \'arcticles\'),
\'edit\' => __(\'Editar\', \'arcticles\'),
\'edit_item\' => __(\'Editar arcticle\', \'arcticles\'),
\'new_item\' => __(\'Novo arcticle\', \'arcticles\'),
\'view\' => __(\'Ver arcticle\', \'arcticles\'),
\'view_item\' => __(\'Ver arcticle\', \'arcticles\'),
\'search_items\' => __(\'Procurar por arcticles\', \'arcticles\'),
\'not_found\' => __(\'Nenhum arcticle encontrado\', \'arcticles\'),
\'not_found_in_trash\' => __(\'Nenhum arcticle encontrado no lixo\', \'arcticles\')
),
\'public\' => true,
\'hierarchical\' => false, // Allows your posts to behave like Hierarchy Pages
\'has_archive\' => true,
\'supports\' => array(
\'title\',
\'excerpt\'
),
\'can_export\' => true,
\'taxonomies\' => array(
\'post_tag\',
\'category\'
), // Add categories and tags
\'register_meta_box_cb\' => \'add_link_metaboxes\'
));
}
// Add the meta box
function add_link_metaboxes () {
add_meta_box( \'linkToArcticle\', \'Link to arcticle\', \'linkToArcticle\', \'arcticles\', \'default\', \'normal\' );
}
// Add Metabox content
function linkToArcticle() {
global $post;
// Noncename seems to be obligatory
echo \'<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="\' .
wp_create_nonce( plugin_basename(__FILE__) ) . \'" />\';
// Pegar o link se ele já foi gerado
$link = get_post_meta($post->ID, \'_link\', true);
// Echo the link\'s field
echo \'<input type="text" name="_link" value="\' . $link . \'" class="widefat" />\';
}
最合适的回答,由SO网友:RaneWrites 整理而成
中的最后两个参数add_meta_box()
已切换。请查看您旁边的教程中的代码:
// tutorial code
add_meta_box(\'wpt_events_location\', \'Event Location\', \'wpt_events_location\', \'events\', \'side\', \'default\');
// your code
add_meta_box( \'linkToArcticle\', \'Link to arcticle\', \'linkToArcticle\', \'arcticles\', \'default\', \'normal\' );
将其更改为:
add_meta_box( \'linkToArcticle\', \'Link to arcticle\', \'linkToArcticle\', \'arcticles\', \'normal\', \'default\' );
它会起作用的