_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: 這是一個私有函式,用於在管理區預覽文章時過濾與該文章相關的術語。它用於確保在預覽文章時顯示正確的術語,即使術語在文章最後一次儲存後被改變。

過濾術語查詢,以設定文章的格式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
檢視更多 >