WordPress开发者和主题制作者的搜索引擎



wp_get_post_revisions ›

Since2.6.0
已弃用n/a
wp_get_post_revisions ( $post_id = 0, $args = null )
参数: (2)
  • (int|WP_Post) $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
    Required: No
    默认:
  • (array|null) $args Optional. Arguments for retrieving post revisions. Default null.
    Required: No
    默认: null
查看:
返回:
  • (array) An array of revisions, or an empty array if none.
定义在:
文档:

Returns all revisions of specified post.



源码

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',
		)
	);

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

	return $revisions;
}