Yoast\WP\SEO\Builders
Indexable_Hierarchy_Builder::add_ancestors_for_post()
Adds ancestors for a post.
Метод класса: Indexable_Hierarchy_Builder{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->add_ancestors_for_post( $indexable_id, $post_id, $parents );
- $indexable_id(int) (обязательный)
- The indexable id, this is the id of the original indexable.
- $post_id(int) (обязательный)
- The post id, this is the id of the post currently being evaluated.
- $parents(int[]) (обязательный) (передается по ссылке — &)
- The indexable IDs of all parents.
Код Indexable_Hierarchy_Builder::add_ancestors_for_post() Indexable Hierarchy Builder::add ancestors for post Yoast 24.4
private function add_ancestors_for_post( $indexable_id, $post_id, &$parents ) { $post = $this->post->get_post( $post_id ); if ( ! isset( $post->post_parent ) ) { return; } if ( $post->post_parent !== 0 && $this->post->get_post( $post->post_parent ) !== null ) { $ancestor = $this->indexable_repository->find_by_id_and_type( $post->post_parent, 'post' ); if ( $this->is_invalid_ancestor( $ancestor, $indexable_id, $parents ) ) { return; } $parents[ $this->get_indexable_id( $ancestor ) ] = $ancestor; $this->add_ancestors_for_post( $indexable_id, $ancestor->object_id, $parents ); return; } $primary_term_id = $this->find_primary_term_id_for_post( $post ); if ( $primary_term_id === 0 ) { return; } $ancestor = $this->indexable_repository->find_by_id_and_type( $primary_term_id, 'term' ); if ( $this->is_invalid_ancestor( $ancestor, $indexable_id, $parents ) ) { return; } $parents[ $this->get_indexable_id( $ancestor ) ] = $ancestor; $this->add_ancestors_for_term( $indexable_id, $ancestor->object_id, $parents ); }