For NEW post type ‘post’ use draft_to_publish
action hook:
function fpw_post_info( $post ) {
if ( 'post' == $post->post_type ) {
// echo '<pre>'; print_r( $post ); echo '<br />';
// $meta = get_post_meta( $post->ID ); print_r( $meta ); echo '</pre>'; die();
// your custom code goes here...
}
}
add_action( 'draft_to_publish', 'fpw_post_info', 10, 1 );
In your callback function $post
is your post as WP_post
object. You’ll get post’s meta calling get_post_meta
function.
For NEW or UPDATED post type ‘post’ use publish_post
action hook:
function fpw_post_info( $id, $post ) {
// echo '<pre>'; print_r( $post ); echo '<br />';
// $meta = get_post_meta( $post->ID ); print_r( $meta ); echo '</pre>'; die();
// your custom code goes here...
}
add_action( 'publish_post', 'fpw_post_info', 10, 2 );
In this case the callback function takes two parameters!