update_post_caches() - WordPress 函数参考中文文档

返回介绍

update_post_caches()

发布于 2017-09-11 字数2502 浏览 870 评论 0

update_post_caches( array $posts,  string $post_type = 'post',  bool $update_term_cache = true,  bool $update_meta_cache = true )

Call major cache updating functions for list of Post objects.


描述


参数

$posts

(array)
(Required)
Array of Post objects

$post_type

(string)
(Optional)
Post type.

Default value: ‘post’

$update_term_cache

(bool)
(Optional)
Whether to update the term cache.

Default value: true

$update_meta_cache

(bool)
(Optional)
Whether to update the meta cache.

Default value: true


源代码

File: wp-includes/post.php

function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) {
	// No point in doing all this work if we didn't match any posts.
	if ( !$posts )
		return;

	update_post_cache($posts);

	$post_ids = array();
	foreach ( $posts as $post )
		$post_ids[] = $post->ID;

	if ( ! $post_type )
		$post_type = 'any';

	if ( $update_term_cache ) {
		if ( is_array($post_type) ) {
			$ptypes = $post_type;
		} elseif ( 'any' == $post_type ) {
			$ptypes = array();
			// Just use the post_types in the supplied posts.
			foreach ( $posts as $post ) {
				$ptypes[] = $post->post_type;
			}
			$ptypes = array_unique($ptypes);
		} else {
			$ptypes = array($post_type);
		}

		if ( ! empty($ptypes) )
			update_object_term_cache($post_ids, $ptypes);
	}

	if ( $update_meta_cache )
		update_postmeta_cache($post_ids);
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/taxonomy.php:
    update_object_term_cache()
  • wp-includes/post.php:
    update_postmeta_cache()
  • wp-includes/post.php:
    update_post_cache()

Used By

  • wp-includes/class-wp-query.php:
    WP_Query::get_posts()
  • wp-includes/post.php:
    _prime_post_caches()

User Contributed Notes

上一篇:update_posts_count()

下一篇:update_post_meta()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!