0

I want to show my metabox in post.php?action=edit not in post-new.php. How can I do that?

2
  • How about applying if ( !empty( $_REQUEST['action'] ) && "edit" == $_REQUEST['action'] ) { /* proceed */ } in the function which outputs the metabox content?
    – Ismail
    Commented Jul 10, 2016 at 14:34
  • test the post_status value which is auto-draft when creating a new post
    – mmm
    Commented Jul 10, 2016 at 15:45

1 Answer 1

0

One simple solution is to check with the query string from the request:

if ( !empty( $_REQUEST['action'] ) && "edit" == $_REQUEST['action'] ) {
  /* proceed */
}

But it is also a good practice to use @mmm's suggestion since you are working with meta boxes where you have the $post object in use. When composing a new post, there's an automatically created post with a status of auto-draft, so let's proceed the meta box coding when the status is something other than auto-draft, say publish for instance:

if ( !empty( ( $status = get_post_status( $post->ID ) ) ) && "auto-draft" !== $status ) {
  /* proceed */
}

Glad that helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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