1

I'm creating a WordPress plugin where it is required to show the meta box only when a post is being published for the first time.

The only way I can think of is to show the metabox iff there is no $_GET['post'] parameter set(it represents the post ID), but then meta box will not be visible for the posts which are in draft.

Is there any way to determine if the post has been published before?

0

I haven't tested this but the idea is to check the post status, if the post is not published, show the metabox otherwise don't.

function non_publish_metaboxes() {
    global $post;

    if(!isset($post))
        return;

    if($post->post_status !== 'publish'){
        // ... Show Metabox
    }
}
add_action( 'add_meta_boxes', 'non_publish_metaboxes' );
0

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.