wp_is_post_autosave() WordPress Function

The wp_is_post_autosave() function is used to check if the current post is an autosave.

wp_is_post_autosave( int|WP_Post $post ) #

Determines if the specified post is an autosave.


Parameters

$post

(int|WP_Post)(Required)Post ID or post object.


Top ↑

Return

(int|false) ID of autosave's parent on success, false if not a revision.


Top ↑

Source

File: wp-includes/revision.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;
}


Top ↑

Changelog

Changelog
VersionDescription
2.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.