I tend to make use of the transition_post_status
hook as it gives you so much control over what you need to do. Be sure to check out the link for all available status options. What I specially like that the $post
object is also passed to the hook, so you can target a specific post type as well for one.
You can try something like the following: (Just be sure to update the values to your own, I just used mine as example)
add_action( 'transition_post_status', function ( $new_status, $old_status, $post )
{
// Check if we are transitioning from pending to publish
if ( $old_status == 'pending' && $new_status == 'publish' ) {
// Check whether or not the meta_key exists already with our value
if ( ! add_post_meta( $post->ID, 'post_views_count', 50, true ) ) {
update_post_meta ( $post->ID, 'post_views_count', 50 );
}
}
}, 10, 3 );