wp_queue_posts_for_term_meta_lazyload

函式
wp_queue_posts_for_term_meta_lazyload ( $posts )
引數
  • (WP_Post[]) $posts Array of WP_Post objects.
    Required:
定義位置
相關方法
wp_queue_comments_for_comment_meta_lazyloadwp_enqueue_stored_styleswp_nav_menu_post_type_meta_boxeswp_nav_menu_item_post_type_meta_boxpost_format_meta_box
引入
4.5.0
棄用
-

wp_queue_posts_for_term_meta_lazyload: 這個函式用於排隊等待術語後設資料的載入。它通過只在需要時載入術語後設資料來提高網站的效能。

為懶惰地載入術語元而排隊發帖。

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 );
	}
}

常見問題

FAQs
檢視更多 >