I want to show my metabox in post.php?action=edit
not in post-new.php
. How can I do that?
1 Answer
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.
if ( !empty( $_REQUEST['action'] ) && "edit" == $_REQUEST['action'] ) { /* proceed */ }
in the function which outputs the metabox content?post_status
value which isauto-draft
when creating a new post