wp_queue_posts_for_term_meta_lazyload() WordPress Function

This function queues up posts for lazy-loading term meta data. It does this by first checking if the current term has any meta data associated with it. If not, it then queries the database for all posts that have that term assigned to them. Once it has a list of posts, it then goes through and lazy-loads the term meta data for each post.

wp_queue_posts_for_term_meta_lazyload( array $posts ) #

Queues posts for lazy-loading of term meta.


Parameters

$posts

(array)(Required)Array of WP_Post objects.


Top ↑

Source

File: wp-includes/post.php

function wp_queue_posts_for_term_meta_lazyload( $posts ) {
	$post_type_taxonomies = array();
	$term_ids             = array();
	foreach ( $posts as $post ) {
		if ( ! ( $post instanceof WP_Post ) ) {
			continue;
		}

		if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) {
			$post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type );
		}

		foreach ( $post_type_taxonomies[ $post->post_type ] as $taxonomy ) {
			// Term cache should already be primed by `update_post_term_cache()`.
			$terms = get_object_term_cache( $post->ID, $taxonomy );
			if ( false !== $terms ) {
				foreach ( $terms as $term ) {
					if ( ! in_array( $term->term_id, $term_ids, true ) ) {
						$term_ids[] = $term->term_id;
					}
				}
			}
		}
	}

	if ( $term_ids ) {
		$lazyloader = wp_metadata_lazyloader();
		$lazyloader->queue_objects( 'term', $term_ids );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More