wp_is_post_revision()
Determines whether the specified post is a revision.
Uses: wp_get_post_revision()
1 time — 0.000741 sec (slow) | 50000 times — 1.31 sec (fast)
No Hooks.
Returns
Int|false.
- False — not a revision.
- ID of the post that the current post is a revision of.
Usage
wp_is_post_revision( $post );
- $post(number/WP_Post) (required)
- ID of the post or its object (WP_Post).
Examples
#1 Checking that we are not editing a revision
This is an example from the WordPress function add_post_meta() code. Where before adding metadata to a post, it checks if the post is not a revision:
function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
// make sure that the current post is not a revision.
if ( $the_post = wp_is_post_revision( $post_id ) ) {
$post_id = $the_post;
}
return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
}
Changelog
| Since 2.6.0 | Introduced. |
wp_is_post_revision() wp is post revision code WP 6.9.1
function wp_is_post_revision( $post ) {
$post = wp_get_post_revision( $post );
if ( ! $post ) {
return false;
}
return (int) $post->post_parent;
}