Powered By Blogger

Wednesday, August 15, 2018

Execute function when post is published in wordpress

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
}

No comments:

Post a Comment