函数文档

wp_is_post_revision()

💡 云策文档标注

概述

wp_is_post_revision() 函数用于判断指定文章是否为修订版本。它接受文章ID或文章对象作为参数,返回修订父文章的ID或false。

关键要点

  • 参数 $post 可以是整数(文章ID)或 WP_Post 对象,必需
  • 返回值:成功时返回修订父文章的ID(整数),如果不是修订则返回 false
  • 内部实现基于 wp_get_post_revision() 函数来获取修订对象
  • 函数自 WordPress 2.6.0 版本引入

代码示例

function wp_is_post_revision( $post ) {
	$post = wp_get_post_revision( $post );

	if ( ! $post ) {
		return false;
	}

	return (int) $post->post_parent;
}

注意事项

  • 函数主要用于检测文章是否为修订,常用于处理修订相关逻辑
  • 相关函数包括 wp_get_post_revision()、wp_post_revision_title() 等,用于获取修订信息

📄 原文内容

Determines if the specified post is a revision.

Parameters

$postint|WP_Postrequired
Post ID or post object.

Return

int|false ID of revision’s parent on success, false if not a revision.

Source

function wp_is_post_revision( $post ) {
	$post = wp_get_post_revision( $post );

	if ( ! $post ) {
		return false;
	}

	return (int) $post->post_parent;
}

Changelog

Version Description
2.6.0 Introduced.