_wp_preview_terms_filter

函数
_wp_preview_terms_filter ( $terms, $post_id, $taxonomy )
Access
Private
参数
  • (array) $terms
    Required:
  • (int) $post_id
    Required:
  • (string) $taxonomy
    Required:
返回值
  • (array)
定义位置
相关方法
preview_theme_ob_filter_preview_theme_stylesheet_filter_wp_preview_post_thumbnail_filter_preview_theme_template_filterwp_print_theme_file_tree
引入
3.6.0
弃用
-

_wp_preview_terms_filter: 这是一个私有函数,用于在管理区预览文章时过滤与该文章相关的术语。它用于确保在预览文章时显示正确的术语,即使术语在文章最后一次保存后被改变。

过滤术语查询,以设置文章的格式。

function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
	$post = get_post();

	if ( ! $post ) {
		return $terms;
	}

	if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id
		|| 'post_format' !== $taxonomy || 'revision' === $post->post_type
	) {
		return $terms;
	}

	if ( 'standard' === $_REQUEST['post_format'] ) {
		$terms = array();
	} else {
		$term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' );
		if ( $term ) {
			$terms = array( $term ); // Can only have one post format.
		}
	}

	return $terms;
}

常见问题

FAQs
查看更多 >