WPSEO_Sitemap_Image_Parser::prime_thumbnail_caches
Primes the meta caches of the featured images of the given posts.
This parser reads each post's featured image file location from the attachment's meta individually; warming that meta cache in bulk avoids one query per post on setups without a persistent object cache.
Метод класса: WPSEO_Sitemap_Image_Parser{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$WPSEO_Sitemap_Image_Parser = new WPSEO_Sitemap_Image_Parser(); $WPSEO_Sitemap_Image_Parser->prime_thumbnail_caches( $posts );
- $posts(WP_Post[]) (обязательный)
- The posts to prime the featured-image caches for.
Код WPSEO_Sitemap_Image_Parser::prime_thumbnail_caches() WPSEO Sitemap Image Parser::prime thumbnail caches Yoast 28.9
public function prime_thumbnail_caches( $posts ) {
$thumbnail_ids = [];
foreach ( $posts as $post ) {
$thumbnail_id = get_post_thumbnail_id( $post );
if ( $thumbnail_id ) {
$thumbnail_ids[] = $thumbnail_id;
}
}
if ( ! empty( $thumbnail_ids ) ) {
update_meta_cache( 'post', array_unique( $thumbnail_ids ) );
}
}