Yoast\WP\SEO\Repositories
Indexable_Repository::get_ancestors()
Returns all ancestors of a given indexable.
Метод класса: Indexable_Repository{}
Хуков нет.
Возвращает
Indexable[]
. All ancestors of the given indexable.
Использование
$Indexable_Repository = new Indexable_Repository(); $Indexable_Repository->get_ancestors( $indexable );
- $indexable(Indexable) (обязательный)
- The indexable to find the ancestors of.
Код Indexable_Repository::get_ancestors() Indexable Repository::get ancestors Yoast 24.0
public function get_ancestors( Indexable $indexable ) { // If we've already set ancestors on the indexable no need to get them again. if ( \is_array( $indexable->ancestors ) && ! empty( $indexable->ancestors ) ) { return \array_map( [ $this, 'upgrade_indexable' ], $indexable->ancestors ); } $indexable_ids = $this->hierarchy_repository->find_ancestors( $indexable ); // If we've set ancestors on the indexable because we had to build them to find them. if ( \is_array( $indexable->ancestors ) && ! empty( $indexable->ancestors ) ) { return \array_map( [ $this, 'upgrade_indexable' ], $indexable->ancestors ); } if ( empty( $indexable_ids ) ) { return []; } if ( $indexable_ids[0] === 0 && \count( $indexable_ids ) === 1 ) { return []; } $indexables = $this->query() ->where_in( 'id', $indexable_ids ) ->order_by_expr( 'FIELD(id,' . \implode( ',', $indexable_ids ) . ')' ) ->find_many(); return \array_map( [ $this, 'upgrade_indexable' ], $indexables ); }