WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to register a metabox in my WordPress custom post, but only in case the post is permanent saved in database.

What I mean, when the user click on "Add new" I don't want to display the metabox. When the user click on "Publish" after the page refresh display the metabox.

The post status doesn't matter (published, private or what ever)

Any idea ?

share|improve this question
up vote 5 down vote accepted

As an alternative to @m0r7if3r's solution, the add_meta_boxes hook optionally passes two variables, the post type and post object. You can use this to conditionally add your metabox. New posts have the post status of 'auto-draft'.

add_action( 'add_meta_boxes', 'myplugin_add_custom_box',10,2);
function myplugin_add_custom_box($post_type, $post) {
    if($post->post_status != 'auto-draft'){
         __( 'My Post Section Title', 'myplugin_textdomain' ),
         'post' );
share|improve this answer
+1 really solid solution...I'd be interested to see if it outperformed mine in real-world usage. – mor7ifer Mar 7 '12 at 18:19

You should be able to filter the call to add_meta_box() conditionally using the $current_screen variable or get_current_screen(). The only time that the user shouldn't see the box is on post-new.php, once they leave that page, some form of saving has been done.

share|improve this answer
How to use the $current_screen, and the get_current_screen(). Any tutorial? I user the $current_screen with global $current_screen; echo $current_screen and I get no response, and I user the get_current_screen() and I get a PHP error, function not exists :( – Merianos Nikos Mar 7 '12 at 18:15
You can view what's in $current_screen with print_r(). It's not available until after the admin_head hook though, so make sure you're hooking into admin_head or something around there. – mor7ifer Mar 7 '12 at 18:17
Nice ! thanks ! – Merianos Nikos Mar 7 '12 at 18:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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