WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Авторские Темы для WordPress
функция не описана

WPSEO_Meta::keyword_usage() public Yoast 1.0

Counts the total of all the keywords being used for posts except the given one.

{} Это метод класса: WPSEO_Meta{}

Хуков нет.

Возвращает

Массив. Ничего.

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

$result = WPSEO_Meta::keyword_usage( $keyword, $post_id );
$keyword(строка) (обязательный)
The keyword to be counted.
$post_id(числоeger) (обязательный)
The id of the post to which the keyword belongs.

Код WPSEO_Meta::keyword_usage() Yoast 16.2

<?php
public static function keyword_usage( $keyword, $post_id ) {

	if ( empty( $keyword ) ) {
		return [];
	}

	/**
	 * The indexable repository.
	 *
	 * @var Indexable_Repository
	 */
	$repository = YoastSEO()->classes->get( Indexable_Repository::class );

	$post_ids = $repository->query()
		->select( 'object_id' )
		->where( 'primary_focus_keyword', $keyword )
		->where( 'object_type', 'post' )
		->where_not_equal( 'object_id', $post_id )
		->limit( 2 )
		->find_array();

	$callback = function ( $row ) {
		return (int) $row['object_id'];
	};
	$post_ids = array_map( $callback, $post_ids );

	/*
	 * If Yoast SEO Premium is active, get the additional keywords as well.
	 * We only check for the additional keywords if we've not already found two.
	 * In that case there's no use for an additional query as we already know
	 * that the keyword has been used multiple times before.
	 */
	if ( YoastSEO()->helpers->product->is_premium() && count( $post_ids ) < 2 ) {
		$query = [
			'meta_query'     => [
				[
					'key'     => '_yoast_wpseo_focuskeywords',
					'value'   => sprintf( '"keyword":"%s"', $keyword ),
					'compare' => 'LIKE',
				],
			],
			'post__not_in'   => [ $post_id ],
			'fields'         => 'ids',
			'post_type'      => 'any',

			/*
			 * We only need to return zero, one or two results:
			 * - Zero: keyword hasn't been used before
			 * - One: Keyword has been used once before
			 * - Two or more: Keyword has been used twice or more before
			 */
			'posts_per_page' => 2,
		];
		$get_posts = new WP_Query( $query );
		$post_ids  = array_merge( $post_ids, $get_posts->posts );
	}

	return $post_ids;
}