wp_is_post_autosave()
Determines if the specified post is an autosave.
Uses: wp_get_post_revision()
1 time — 0.001271 sec (very slow) | 50000 times — 0.22 sec (very fast) | PHP 7.1.5, WP 4.8.2
No Hooks.
Return
Int|false
. ID of autosave's parent on success, false if not a revision.
Usage
wp_is_post_autosave( $post );
- $post(int|WP_Post) (required)
- Post ID or post object.
Examples
#1 Check if the specified post is an autosave (revision)
$post_id = 20; if ( wp_is_post_autosave( $post_id ) ) { return; }
Changelog
Since 2.6.0 | Introduced. |
wp_is_post_autosave() wp is post autosave code WP 6.6.2
function wp_is_post_autosave( $post ) { $post = wp_get_post_revision( $post ); if ( ! $post ) { return false; } if ( str_contains( $post->post_name, "{$post->post_parent}-autosave" ) ) { return (int) $post->post_parent; } return false; }