_wp_preview_meta_filter

函数
_wp_preview_meta_filter ( $value, $object_id, $meta_key, $single )
参数
  • (mixed) $value Meta value to filter.
    Required:
  • (int) $object_id Object ID.
    Required:
  • (string) $meta_key Meta key to filter a value for.
    Required:
  • (bool) $single Whether to return a single value. Default false.
    Required:
返回值
  • (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.
定义位置
相关方法
_wp_preview_terms_filter_preview_theme_template_filter_wp_preview_post_thumbnail_filterpreview_theme_ob_filter_preview_theme_stylesheet_filter
引入
6.4.0
弃用
-

过滤预览后元检索,从自动保存中获取值。仅过滤已修订的元键。

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 );
}

常见问题

FAQs
查看更多 >