Yoast\WP\SEO\Integrations\Watchers
Indexable_Ancestor_Watcher::get_object_ids_for_term() protected Yoast 1.0
Retrieves the object id's for a term based on the term-post relationship.
{} Это метод класса: Indexable_Ancestor_Watcher{}
Хуков нет.
Возвращает
Массив. List with object ids for the term.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_object_ids_for_term( $term_id, $child_indexables );
- $term_id(число) (обязательный)
- The term to get the object id's for.
- $child_indexables(Indexable[]) (обязательный)
- The child indexables.
Код Indexable_Ancestor_Watcher::get_object_ids_for_term() Indexable Ancestor Watcher::get object ids for term Yoast 15.6.2
protected function get_object_ids_for_term( $term_id, $child_indexables ) {
$filter_terms = function( $child ) {
return $child->object_type === 'term';
};
$child_terms = \array_filter( $child_indexables, $filter_terms );
$child_object_ids = \wp_list_pluck( $child_terms, 'object_id' );
// Get the term-taxonomy id's for the term and its children.
$term_taxonomy_ids = $this->wpdb->get_col(
$this->wpdb->prepare(
'SELECT term_taxonomy_id
FROM ' . $this->wpdb->term_taxonomy . '
WHERE term_id IN( ' . \implode( ', ', \array_fill( 0, ( \count( $child_object_ids ) + 1 ), '%s' ) ) . ' )',
$term_id,
...$child_object_ids
)
);
// In the case of faulty data having been saved the above query can return 0 results.
if ( empty( $term_taxonomy_ids ) ) {
return [];
}
// Get the (post) object id's that are attached to the term.
return $this->wpdb->get_col(
$this->wpdb->prepare(
'SELECT DISTINCT object_id
FROM ' . $this->wpdb->term_relationships . '
WHERE term_taxonomy_id IN( ' . \implode( ', ', \array_fill( 0, \count( $term_taxonomy_ids ), '%s' ) ) . ' )',
...$term_taxonomy_ids
)
);
}