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



_wp_preview_meta_filter › WordPress Function

Since6.4.0
已弃用n/a
_wp_preview_meta_filter ( $value, $object_id, $meta_key, $single )
参数: (4)
  • (mixed) $value Meta value to filter.
    Required: Yes
  • (int) $object_id Object ID.
    Required: Yes
  • (string) $meta_key Meta key to filter a value for.
    Required: Yes
  • (bool) $single Whether to return a single value. Default false.
    Required: Yes
返回:
  • (mixed) Original meta value if the meta key isn't revisioned, the object doesn't exist, the post type is a revision or the post ID doesn't match the object ID. Otherwise, the revisioned meta value is returned for the preview.
定义在:
文档:

Filters preview post meta retrieval to get values from the autosave.

Filters revisioned meta keys only.


源码

function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) {

	$post = get_post();
	if (
		empty( $post ) ||
		$post->ID !== $object_id ||
		! in_array( $meta_key, wp_post_revision_meta_keys( $post->post_type ), true ) ||
		'revision' === $post->post_type
	) {
		return $value;
	}

	$preview = wp_get_post_autosave( $post->ID );
	if ( false === $preview ) {
		return $value;
	}

	return get_post_meta( $preview->ID, $meta_key, $single );
}