我使用选项树框架创建了一个自定义元框。它显示每个页面。我希望它只显示特定页面。我怎么能这样做?
我已将此代码写入functions.php文件
add_action( 'admin_init', 'custom_meta_boxes' );
function custom_meta_boxes() {
$latest_work = array(
'id' => 'latest_work',
'title' => 'latest-work Meta Box',
'desc' => '',
'pages' => array( 'page' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => 'latest-work',
'id' => 'latest-work',
'type' => 'text',
'desc' => 'Tell about your latest work',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
)
)
);
ot_register_meta_box( $latest_work );
}
请告诉我该怎么做?
答案 0 :(得分:0)
add_action( 'admin_menu', 'remove_post_meta_boxes' );
function remove_post_meta_boxes() {
// lets assume blog page has the id 23
// let's remove the meta box from blog
if( isset($_GET['post']) && $_GET['post'] == 23 ){
remove_meta_box( 'latest_work', 'page', 'normal' );
}
}
查看更多信息remove_meta_box()
答案 1 :(得分:0)
使用以下内容。
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
// checks for post/page ID for example i have added 7
if ($post_id == '7'){
/.add_meta box code inside
}