Yoast\WP\SEO\Builders

Primary_Term_Builder::save_primary_term()protectedYoast 1.0

Save the primary term for a specific taxonomy.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->save_primary_term( $post_id, $taxonomy );
$post_id(int) (обязательный)
Post ID to save primary term for.
$taxonomy(строка) (обязательный)
Taxonomy to save primary term for.

Код Primary_Term_Builder::save_primary_term() Yoast 22.3

protected function save_primary_term( $post_id, $taxonomy ) {
	$term_id = $this->meta->get_value( 'primary_' . $taxonomy, $post_id );

	$term_selected = ! empty( $term_id );
	$primary_term  = $this->repository->find_by_post_id_and_taxonomy( $post_id, $taxonomy, $term_selected );

	// Removes the indexable when no term found.
	if ( ! $term_selected ) {
		if ( $primary_term ) {
			$primary_term->delete();
		}

		return;
	}

	$primary_term->term_id  = $term_id;
	$primary_term->post_id  = $post_id;
	$primary_term->taxonomy = $taxonomy;
	$primary_term->blog_id  = \get_current_blog_id();
	$primary_term->save();
}