• I am currently writing a function, where I need to get the ID’s of the two latest revisions, when a post is saved. However, the revisions ID’s I get is one behind – it’s not the 2 latest, but the 2nd and 3rd latest ID’s that I get.

    I use the following approach:

    function check_values( $post_ID, $post ) {
        $revisions = wp_get_post_revisions($post_ID);
        $rev1 = array_shift($revisions);
        $rev2 = array_shift($revisions);
        $rev1 = $rev1->ID;
        $rev2 = $rev2->ID;
    }
    
    add_action( 'publish_post', 'check_values', 10, 2 );

    IE – when saving, I could end up with the ID’s 5001 and 5002, where the newest revision is actually 5003.

  • The topic ‘revision id is one number behind – publish_post’ is closed to new replies.