wordpress中的屏幕选项不适用于新的自定义元框

时间:2014-05-07 09:10:15

标签: javascript php jquery html wordpress

我创建了一个名为“我的自定义设置”的元框,它在wordpress中发布,带有一个输入文本框字段。在上面的帖子页面中,我看到了带有预定义“屏幕显示”的屏幕选项菜单。添加新的“我的自定义设置”元框后,它也可用于该屏幕选项。

我刚刚隐藏了“我的自定义设置”。但仍然似乎在帖子之下。

为什么隐藏屏幕选项时它不会隐藏?

我的代码是,

<?php
add_action( 'add_meta_boxes', 'meta_add_custom_box' );
add_action( 'save_post', 'meta_save_custom_meta_box' );
function meta_add_custom_box( $post ) {
add_meta_box(
'Meta Box', // ID, should be a string
'My Custom Settings', // Meta Box Title
'meta_custom_meta_box_content', // Your call back function, this is where your form field will go
'post', // The post type you want this to show up on, can be post, page, or custom post type
'normal', // The placement of your meta box, can be normal or side
'high' // The priority in which this will be displayed
);
}

function meta_save_custom_meta_box(){
global $post;
// Get our form field
if( $_POST ) :
$meta_custom_meta = esc_attr( $_POST['meta-custom-meta-box'] );
// Update post meta
update_post_meta($post->ID, '_meta_custom_meta', $meta_custom_meta);
endif;
}

function meta_custom_meta_box_content( $post ) {
$meta_custom_meta = get_post_meta($post->ID, '_meta_custom_meta', true);
//meta title with character counting
echo '<p><label>Custom Title:</label></p>';
echo '<p><input style="width:99%;" class="meta-text" type="text" name="meta-custom-meta-box" value="'.$meta_custom_meta.'" /></p>';
}
?>

我是否需要为屏幕选项添加额外的代码才能隐藏?
如果是,请更新我的代码。

1 个答案:

答案 0 :(得分:1)

试试这个

 add_filter('default_hidden_meta_boxes', 'hide_meta_lock', 10, 2);
 function hide_meta_lock($hidden, $screen) {
if ( 'frog' == $screen->base )
    $hidden = array('postexcerpt','Meta Box');
    // removed 'postexcerpt',
return $hidden;
 }