Yoast\WP\SEO\Repositories

Indexable_Hierarchy_Repository::find_ancestors()publicYoast 1.0

Retrieves the ancestors. Create them when empty.

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

Хуков нет.

Возвращает

int[]. The indexable id's of the ancestors in order of grandparent to child.

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

$Indexable_Hierarchy_Repository = new Indexable_Hierarchy_Repository();
$Indexable_Hierarchy_Repository->find_ancestors( $indexable );
$indexable(Indexable) (обязательный)
The indexable to get the ancestors for.

Код Indexable_Hierarchy_Repository::find_ancestors() Yoast 23.8

public function find_ancestors( Indexable $indexable ) {
	$ancestors = $this->query()
		->select( 'ancestor_id' )
		->where( 'indexable_id', $indexable->id )
		->order_by_desc( 'depth' )
		->find_array();

	if ( ! empty( $ancestors ) ) {
		if ( \count( $ancestors ) === 1 && $ancestors[0]['ancestor_id'] === '0' ) {
			return [];
		}
		return \wp_list_pluck( $ancestors, 'ancestor_id' );
	}

	$indexable = $this->builder->build( $indexable );

	return \wp_list_pluck( $indexable->ancestors, 'id' );
}