The error there clearly says that there’s an undefined variable (post
) in your metabox callback function.
So you need to define $post
in your function head:
// The $post variable is passed by WordPress.
function diwp_post_metabox_callback( $post )
And you should also do the same to diwp_save_custom_metabox()
function (which is hooked to save_post
):
// Here, $post is the second parameter.
function diwp_save_custom_metabox( $post_ID, $post ) {
// ...
}
// Don't forget to set the 4th parameter to 2:
add_action( 'save_post', 'diwp_save_custom_metabox', 10, 2 );
Or alternatively, use get_post()
and not the global
call:
// Here, $post is the second parameter.
function diwp_save_custom_metabox( $post_ID ) {
$post = get_post( $post_ID ); // like this
// global $post; // not this
// ...
}
add_action( 'save_post', 'diwp_save_custom_metabox' );