metabox - How to hide meta box values from custom fields list?

I have created a metabox :function drama_description_metabox_markup() {global $post;$drama_description_metabox_markup =

I have created a metabox :

function drama_description_metabox_markup() {
    global $post;
    $drama_description_metabox_markup = get_post_meta( $post->ID, 'drama_description', true );
    ?>
        <div>
            <label for="meta-box-text">Description</label>          
            <textarea name="drama_description" style="width: 100%"><?php if ($drama_description_metabox_markup) { echo $drama_description_metabox_markup; }?></textarea>
        </div>
<?php }

function drama_description_metabox(){
    $post_types = array ( 'dramas', 'reality_shows' );
     foreach( $post_types as $post_type )
    {
        $id             = 'drama-description';
        $title          = 'Description';
        $callback       = 'drama_description_metabox_markup';
        $screen         = $post_type;
        $context        = 'normal';
        $priority       = 'high';
        $callback_args  = 'null';
        add_meta_box($id, $title, $callback, $screen, $context, $priority, $callback_args);
    }
}

add_action("add_meta_boxes", "drama_description_metabox");

and the this is how I am saving the meta box value:

function save_drama_description_meta_box($post_id)
{
    global $post;   
    //skip auto save
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return $post_id;
    }
    //check for DRAMAS and REALITY_SHOWS post type only
if( $post->post_type == ("dramas" || "reality_shows") ) {
        if( isset($_POST['drama_description']) ) { 
            update_post_meta( $post->ID, 'drama_description', $_POST['drama_description'] );
        }
    }
}

add_action("save_post", "save_drama_description_meta_box", 10, 3);

Now the meta key drama_description is displayed in both meta box and custom fields list area.

I want to use the custom fields list. So I do not want to hide custom field list box completely.

The above meta key drama_description should be hidden from the custom field list but NOT from the meta box.

I've read some old articles say to prefix the meta keys used for metabox by an underscore _

But I am not sure where to put that underscore. As per my above codes, in which line I have to put the _ to hide the meta key from the custom fields list?

I have created a metabox :

function drama_description_metabox_markup() {
    global $post;
    $drama_description_metabox_markup = get_post_meta( $post->ID, 'drama_description', true );
    ?>
        <div>
            <label for="meta-box-text">Description</label>          
            <textarea name="drama_description" style="width: 100%"><?php if ($drama_description_metabox_markup) { echo $drama_description_metabox_markup; }?></textarea>
        </div>
<?php }

function drama_description_metabox(){
    $post_types = array ( 'dramas', 'reality_shows' );
     foreach( $post_types as $post_type )
    {
        $id             = 'drama-description';
        $title          = 'Description';
        $callback       = 'drama_description_metabox_markup';
        $screen         = $post_type;
        $context        = 'normal';
        $priority       = 'high';
        $callback_args  = 'null';
        add_meta_box($id, $title, $callback, $screen, $context, $priority, $callback_args);
    }
}

add_action("add_meta_boxes", "drama_description_metabox");

and the this is how I am saving the meta box value:

function save_drama_description_meta_box($post_id)
{
    global $post;   
    //skip auto save
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return $post_id;
    }
    //check for DRAMAS and REALITY_SHOWS post type only
if( $post->post_type == ("dramas" || "reality_shows") ) {
        if( isset($_POST['drama_description']) ) { 
            update_post_meta( $post->ID, 'drama_description', $_POST['drama_description'] );
        }
    }
}

add_action("save_post", "save_drama_description_meta_box", 10, 3);

Now the meta key drama_description is displayed in both meta box and custom fields list area.

I want to use the custom fields list. So I do not want to hide custom field list box completely.

The above meta key drama_description should be hidden from the custom field list but NOT from the meta box.

I've read some old articles say to prefix the meta keys used for metabox by an underscore _

But I am not sure where to put that underscore. As per my above codes, in which line I have to put the _ to hide the meta key from the custom fields list?

Share Improve this question asked Sep 10, 2015 at 11:27 foolishcoder7721foolishcoder7721 5811 gold badge8 silver badges19 bronze badges 1
  • meta keys used for metabox by an underscore, this is quite explanory :-). – Pieter Goosen Commented Sep 10, 2015 at 11:36
Add a comment  | 

1 Answer 1

Reset to default 7

Just add an underscore before the metabox ID so the part of your code where you add a metabox looks something like this:

$id             = '_drama-description';
$title          = 'Description';
$callback       = 'drama_description_metabox_markup';
$screen         = $post_type;
$context        = 'normal';
$priority       = 'high';
$callback_args  = 'null';
add_meta_box($id, $title, $callback, $screen, $context, $priority, $callback_args);

You also need to replace every occurance of drama-description to _drama-description in the part where you save the data. Hope it helps.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745612867a4636054.html

相关推荐

  • metabox - How to hide meta box values from custom fields list?

    I have created a metabox :function drama_description_metabox_markup() {global $post;$drama_description_metabox_markup =

    6小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信