wp_queue_posts_for_term_meta_lazyload

Queues posts for lazy-loading of term meta.

Description

wp_queue_posts_for_term_meta_lazyload( (array) $posts ); 

Parameters (1)

0. $posts (array)
Array of WP_Post objects.

Usage

  1. if ( !function_exists( 'wp_queue_posts_for_term_meta_lazyload' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Array of WP_Post objects. 
  5. $posts = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_queue_posts_for_term_meta_lazyload($posts); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function wp_queue_posts_for_term_meta_lazyload( $posts ) { 
  2. $post_type_taxonomies = $term_ids = array(); 
  3. foreach ( $posts as $post ) { 
  4. if ( ! ( $post instanceof WP_Post ) ) { 
  5. continue; 
  6.  
  7. if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) { 
  8. $post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type ); 
  9.  
  10. foreach ( $post_type_taxonomies[ $post->post_type ] as $taxonomy ) { 
  11. // Term cache should already be primed by `update_post_term_cache()`. 
  12. $terms = get_object_term_cache( $post->ID, $taxonomy ); 
  13. if ( false !== $terms ) { 
  14. foreach ( $terms as $term ) { 
  15. if ( ! isset( $term_ids[ $term->term_id ] ) ) { 
  16. $term_ids[] = $term->term_id; 
  17.  
  18. if ( $term_ids ) { 
  19. $lazyloader =wp_metadata_lazyloader); 
  20. $lazyloader->queue_objects( 'term', $term_ids );