Is there a way to get a revision count of a post?

You can use wp_get_post_revisions ( int|WP_Post $post_id, $args = null ). It returns an array of revisions for the passed post ID or an empty array if a passed post does not have any revisions.

Note that the $args parameter accepts all parameters valid for WP_Query

$q = wp_get_post_revisions( 513 );
echo count( $q );
?><pre><?php var_dump($q); ?></pre><?php    

EDIT

From your comments about custom fields, custom fields does not trigger the post revision system.

I’m not going to discuss how the revision system works, but in short, when a post is updated, the old and new values of the WP_Post is compared. There are a specific action for that, post_updated. If these value don’t match, a revision is created (if revisions are enabled).

Now, custom fields are not part of the WP_Post object, there for, whenever you just update a custom field, a post revision will not be created as the post object remains the same. Also, custom fields also don’t have a revision system, so old values are completely overwritten by new values

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)