_wp_preview_terms_filter()WP 3.6.0

Filters terms lookup to set the post format.

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

Массив.

Использование

_wp_preview_terms_filter( $terms, $post_id, $taxonomy );
$terms(массив) (обязательный)
-
$post_id(int) (обязательный)
-
$taxonomy(строка) (обязательный)
-

Список изменений

С версии 3.6.0 Введена.

Код _wp_preview_terms_filter() WP 6.5.2

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