wp_get_post_revisions()获取一篇文章的所有修订版本信息

目录

描述

Returns all revisions of specified post.

wp_get_post_revisions() 描述

用法

<?php wp_get_post_revisions$post_id$args ); ?>

wp_get_post_revisions() 用法

参数

$post_id

(mixed) (必填) Post ID or post object.

默认值: 0

$args

(array) (可选) Query arguments

默认值: None

See the parameters section of the WP_Query documentation for a list of parameters that the parameter $args accepts.

wp_get_post_revisions() 参数

返回值

(array

An array of revision objects, or an empty array if none.

wp_get_post_revisions() 返回值

历史

添加于 版本: 2.6

wp_get_post_revisions() 历史

源文件

wp_get_post_revisions() 函数的代码位于 wp-includes/revision.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Returns all revisions of specified post.
 *
 * @since 2.6.0
 *
 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
 * @return array An array of revisions, or an empty array if none.
 */
function wp_get_post_revisions( $post_id = 0, $args = null ) {
	$post = get_post( $post_id );
	if ( ! $post || empty( $post->ID ) )
		return array();

	$defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true );
	$args = wp_parse_args( $args, $defaults );

	if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) )
		return array();

	$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );

	if ( ! $revisions = get_children( $args ) )
		return array();

	return $revisions;
}

wp_get_post_revisions() 源文件

相关