0

Hi I am using a future_post hook to capture when a scheduled post is updated like so :

add_action('future_post', 'on_post_scheduled');

Then I want to send the new post date to a database, however $post->post_date returns the date prior to updating the post. I have to update the post again to get the correct new date.

Within the on_post_scheduled function I am using the global $post to access the post date, is this the cause?

0
function on_post_scheduled( $post_id, $post ) {

    // If this is just a revision, don't do anything.
    if ( wp_is_post_revision( $post_id ) )
        return;
    // If this is a 'post' post and post status is future.
    if ( ('post' == $post->post_type) && ('future' == $post->post_status)) {
        // do the thing zhu li!
        wp_die('<pre>'.print_r($post,true).'</pre>');
    }

}
add_action( 'save_post', 'on_post_scheduled', 10, 2 );

it's best to add action on save_post like this... and just check the post type and post status...

  • Thanks Reigel, How does this solve the date being wrong? – Frank Astin Jan 24 '15 at 13:42
  • save_post is an action triggered whenever a post or page is created or updated. So before it saves the all the data, it goes in this action.... try do a return false here and data are not saved... – Reigel Jan 24 '15 at 13:57
  • I put there wp_die('<pre>'.print_r($post,true).'</pre>'); for you to see if the date is correct... For which I'm confident it is... – Reigel Jan 24 '15 at 13:58

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.