функция since 2.5.0

get_the_taxonomies()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

get_the_taxonomies( int|WP_Post $post, array $args = array() ): string[]

Описание

Эту функцию можно использовать внутри цикла. Она также возвращает массив таксономий со ссылками на таксономию и названием.

Оригинал (английский)

This function can be used within the loop. It will also return an array of the taxonomies with links to the taxonomy and name.

Параметры

$post int|WP_Post необязательный
ID записи или объект WP_Post. По умолчанию — глобальная переменная $post.
$args array необязательный = array()
Аргументы, определяющие форматирование списка таксономий. template stringШаблон для отображения метки таксономии и списка терминов. По умолчанию "Label: Terms." term_template stringШаблон для отображения одного термина в списке. По умолчанию — название термина со ссылкой на его архив.

Возвращаемое значение

string[]

Исходный код

wp-includes/taxonomy.php:4824

function get_the_taxonomies( $post = 0, $args = array() ) {
	$post = get_post( $post );

	$args = wp_parse_args(
		$args,
		array(
			/* translators: %s: Taxonomy label, %l: List of terms formatted as per $term_template. */
			'template'      => __( '%s: %l.' ),
			'term_template' => '<a href="%1$s">%2$s</a>',
		)
	);

	$taxonomies = array();

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

	foreach ( get_object_taxonomies( $post ) as $taxonomy ) {
		$t = (array) get_taxonomy( $taxonomy );
		if ( empty( $t['label'] ) ) {
			$t['label'] = $taxonomy;
		}
		if ( empty( $t['args'] ) ) {
			$t['args'] = array();
		}
		if ( empty( $t['template'] ) ) {
			$t['template'] = $args['template'];
		}
		if ( empty( $t['term_template'] ) ) {
			$t['term_template'] = $args['term_template'];
		}

		$terms = get_object_term_cache( $post->ID, $taxonomy );
		if ( false === $terms ) {
			$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
		}
		$links = array();

		foreach ( $terms as $term ) {
			$links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link( $term ) ), $term->name );
		}
		if ( $links ) {
			$taxonomies[ $taxonomy ] = wp_sprintf( $t['template'], $t['label'], $links, $terms );
		}
	}
	return $taxonomies;
}

История изменений

ВерсияОписание
2.5.0 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.