WPSEO_Taxonomy_Meta::get_keyword_usage()public staticYoast 1.0

Find the keyword usages in the metas for the taxonomies/terms.

Метод класса: WPSEO_Taxonomy_Meta{}

Хуков нет.

Возвращает

Массив.

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

$result = WPSEO_Taxonomy_Meta::get_keyword_usage( $keyword, $current_term_id, $current_taxonomy );
$keyword(строка) (обязательный)
The keyword to look for.
$current_term_id(строка) (обязательный)
The current term id.
$current_taxonomy(строка) (обязательный)
The current taxonomy name.

Код WPSEO_Taxonomy_Meta::get_keyword_usage() Yoast 22.4

public static function get_keyword_usage( $keyword, $current_term_id, $current_taxonomy ) {
	$tax_meta = self::get_tax_meta();

	$found = [];
	// @todo Check for terms of all taxonomies, not only the current taxonomy.
	foreach ( $tax_meta as $taxonomy_name => $terms ) {
		foreach ( $terms as $term_id => $meta_values ) {
			$is_current = ( $current_taxonomy === $taxonomy_name && (string) $current_term_id === (string) $term_id );
			if ( ! $is_current && ! empty( $meta_values['wpseo_focuskw'] ) && $meta_values['wpseo_focuskw'] === $keyword ) {
				$found[] = $term_id;
			}
		}
	}

	return [ $keyword => $found ];
}