Yoast\WP\SEO\Repositories

Primary_Term_Repository::find_by_post_id_and_taxonomy()publicYoast 1.0

Retrieves a primary term by a post ID and taxonomy.

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

Хуков нет.

Возвращает

Primary_Term|null. Instance of a primary term.

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

$Primary_Term_Repository = new Primary_Term_Repository();
$Primary_Term_Repository->find_by_post_id_and_taxonomy( $post_id, $taxonomy, $auto_create );
$post_id(int) (обязательный)
The post the indexable is based upon.
$taxonomy(строка) (обязательный)
The taxonomy the indexable belongs to.
$auto_create(true|false)
Creates an indexable if it does not exist yet.
По умолчанию: true

Код Primary_Term_Repository::find_by_post_id_and_taxonomy() Yoast 22.4

public function find_by_post_id_and_taxonomy( $post_id, $taxonomy, $auto_create = true ) {
	/**
	 * Instance of the primary term.
	 *
	 * @var Primary_Term $primary_term
	 */
	$primary_term = $this->query()
		->where( 'post_id', $post_id )
		->where( 'taxonomy', $taxonomy )
		->find_one();

	if ( $auto_create && ! $primary_term ) {
		$primary_term = $this->query()->create();
	}

	return $primary_term;
}