0

Before I ask the question, I tried to added _ to the custom field, but it's not working, at least with my code.

I just want to hide the value of my meta box from appearing in the custom fields. When I added _ to the code, the metabox stopped working.

Here's the code:

//Creating a MetaBox for Posts to enter audio Code.
add_action('add_meta_boxes','audio_meta_box');
function audio_meta_box(){
    add_meta_box('audio_box_id', 'Enter Audio ' , 'audio_box_cb','post','normal','default');
}
function audio_box_cb($post){
    $value = get_post_meta($post->ID,'_audio_box',true);

    echo '<textarea rows="1" style="width: 98%;" id="audio_box", name="audio_box">';
        echo $value;
    echo '</textarea>';
}

add_action('save_post','save_audio_box');
function save_audio_box($post_id){
    $box_data = $_POST['audio_box'];
    update_post_meta($post_id,'_audio_box',$box_data, true);
}
  • 1
    I don't see where you prefixed something with _ in the code you are showing, so I guess you are showing the working code, it would be better, I think, if you show the not working code. Besides that I don't see a reasons why prefixing the post meta key audio_box with _ like this _audio_box to make it hidden shouldn't work. – Nicolai Apr 2 '14 at 11:32
  • I have edited the code. I also tried it by adding underscore to $box_data = $_POST['audio_box']; as well. – Hardeep Asrani Apr 2 '14 at 11:34
  • I guess no one so far understood what you mean by "hiding metabox value" – kaiser Apr 2 '14 at 11:40
  • I want to hide the value of metabox from appearing in the custom fields as a custom field. – Hardeep Asrani Apr 2 '14 at 11:41
  • You have some syntax errors, to begin with, the textarea tag has rows and cols as required attributes. Besides you have a comma in your code that shouldn't be there. Additionally I think there is a misunderstanding, because the value of the $_POST variable isn't (necessarily) identical with your post meta, it is determined by the name of the form field, so prefixing it won't do anything for you. Last but not least, it is likely that your are just seeing the old post meta entry, which you haven't prefixed. – Nicolai Apr 2 '14 at 12:16
2

Custom fields or post meta entries can be hidden from the by default in Wordpress available »Cutom Fields«-Metabox by prefixing them with a underscore - _ - as noted here.

As addition, if you want hidden fields to be visible during development you can do that easily - take a look at this answer to know how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.