WPSEO_Replace_Vars::retrieve_primary_category()privateYoast 1.0

Retrieve primary category for use as replacement string.

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

Хуков нет.

Возвращает

true|false|int|null.

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

// private - только в коде основоного (родительского) класса
$result = $this->retrieve_primary_category();

Код WPSEO_Replace_Vars::retrieve_primary_category() Yoast 22.3

private function retrieve_primary_category() {
	$primary_category = null;

	if ( ! empty( $this->args->ID ) ) {
		$wpseo_primary_category = new WPSEO_Primary_Term( 'category', $this->args->ID );

		$term_id = $wpseo_primary_category->get_primary_term();
		$term    = get_term( $term_id );

		if ( ! is_wp_error( $term ) && ! empty( $term ) ) {
			$primary_category = $term->name;
		}
	}

	return $primary_category;
}