0

I have to run a function when a post is published. The function checks a custom meta value and works accordingly. I am using couple of hooks for this purpose:

new_to_publish
draft_to_publish
pending_to_publish
auto-draft_to_publish

Now, new_to_publish and auto-draft_to_publish are not working. It looks like these two hooks run much earlier than add_post_meta hook. As a result, my function doesn't get any meta value and doesn't work. I tried:

add_action('new_to_publish', 'my_custom_function', /*high priority value here*/)

But that doesn't work. Any help is appreciated! Thanks!

0

Using transistion_post_status I'm able to retrieve post meta.

add_action( 'transition_post_status', 'post_published', 10, 3 );

function post_published( $new_status, $old_status, $post ) {
    if ( $old_status != 'publish' && $new_status == 'publish' ) {

    $meta = get_post_meta($post->ID);

    echo '<pre>';
    var_dump($meta);
    echo '</pre>';

    die();

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.