I am trying to save a revision of a custom post type. This is what I have to check if the post has a parent:

function save_revision( $post ) {

    if ( $post['submitted'] == true ) {
       $parent_id = wp_is_post_revision( $post['post_id'] );
       ...
    }
} add_action('init', 'save_revision');

The problem is that I always get false for $parent_id even though I know there is a parent post for that post_id.

Any help is appreciated, I have been trying to get this to work forever.

2 Answers
2

I know this is an old thread, but for future reference – the term “revision” in WordPress is a little confusing. It’s not the updated, or revised, post… but the older version. The most updated version is the “parent.”

So, if you’re calling the function wp_is_revision_post() on the current version of the post, it will always return false (and wp_get_post_parent_id() will return NULL) since the current post is not considered a “revision.” You will need to call it on an actual revision, (which would have a different ID from the current version of the post).

Leave a Reply

Your email address will not be published. Required fields are marked *