1
add_action( 'transition_post_status', 'a_new_post', 10, 3 );

function a_new_post( $new_status, $old_status, $post )
{
if ( 'publish' !== $new_status or 'publish' === $old_status )
    return;

if ( 'post' !== $post->post_type )
    return; // restrict the filter to a specific post type

// do something awesome
}

this code will not allow me to hook into a published post. Is there any code that allows me to hook into published post.

0

1 Answer 1

1

Use {status}_{post_type} hook like:

function a_new_post( $postID, $post ) {
    // your awesome stuff goes here
}
add_action( 'publish_post', 'a_new_post', 10, 2 );

It will fire your action when post's status will change from anything to 'publish'.

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.