WordPress at a glance

wp_is_post_autosave() WP 1.0

Determines if the specified post is an autosave.

Works based on: wp_get_post_revision()
✈ 1 time = 0.001271s = very slow | 50000 times = 0.22s = 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.

Changelog

Since 2.6.0 Introduced.

Code of wp is post autosave: wp-includes/revision.php WP 5.4.2

<?php
function wp_is_post_autosave( $post ) {
	$post = wp_get_post_revision( $post );
	if ( ! $post ) {
		return false;
	}

	if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) {
		return (int) $post->post_parent;
	}

	return false;
}

Related Functions

From tag: Conditional tags (all)

More from category: Revisions

No comments
        Log In . Register