_prime_post_parent_id_caches

函数
_prime_post_parent_id_caches ( $ids )
参数
  • (int[]) $ids ID list.
    Required:
定义位置
相关方法
update_post_parent_caches_prime_post_caches_prime_comment_cacheswp_prime_option_caches_prime_term_caches
引入
6.4.0
弃用
-

Prime 缓存,其中包含各种文章对象的父 ID。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _prime_post_parent_id_caches( array $ids ) {
global $wpdb;
$ids = array_filter( $ids, '_validate_cache_id' );
$ids = array_unique( array_map( 'intval', $ids ), SORT_NUMERIC );
if ( empty( $ids ) ) {
return;
}
$cache_keys = array();
foreach ( $ids as $id ) {
$cache_keys[ $id ] = 'post_parent:' . (string) $id;
}
$cached_data = wp_cache_get_multiple( array_values( $cache_keys ), 'posts' );
$non_cached_ids = array();
foreach ( $cache_keys as $id => $cache_key ) {
if ( false === $cached_data[ $cache_key ] ) {
$non_cached_ids[] = $id;
}
}
if ( ! empty( $non_cached_ids ) ) {
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );
if ( $fresh_posts ) {
$post_parent_data = array();
foreach ( $fresh_posts as $fresh_post ) {
$post_parent_data[ 'post_parent:' . (string) $fresh_post->ID ] = (int) $fresh_post->post_parent;
}
wp_cache_add_multiple( $post_parent_data, 'posts' );
}
}
}
function _prime_post_parent_id_caches( array $ids ) { global $wpdb; $ids = array_filter( $ids, '_validate_cache_id' ); $ids = array_unique( array_map( 'intval', $ids ), SORT_NUMERIC ); if ( empty( $ids ) ) { return; } $cache_keys = array(); foreach ( $ids as $id ) { $cache_keys[ $id ] = 'post_parent:' . (string) $id; } $cached_data = wp_cache_get_multiple( array_values( $cache_keys ), 'posts' ); $non_cached_ids = array(); foreach ( $cache_keys as $id => $cache_key ) { if ( false === $cached_data[ $cache_key ] ) { $non_cached_ids[] = $id; } } if ( ! empty( $non_cached_ids ) ) { $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) ); if ( $fresh_posts ) { $post_parent_data = array(); foreach ( $fresh_posts as $fresh_post ) { $post_parent_data[ 'post_parent:' . (string) $fresh_post->ID ] = (int) $fresh_post->post_parent; } wp_cache_add_multiple( $post_parent_data, 'posts' ); } } }
function _prime_post_parent_id_caches( array $ids ) {
	global $wpdb;

	$ids = array_filter( $ids, '_validate_cache_id' );
	$ids = array_unique( array_map( 'intval', $ids ), SORT_NUMERIC );

	if ( empty( $ids ) ) {
		return;
	}

	$cache_keys = array();
	foreach ( $ids as $id ) {
		$cache_keys[ $id ] = 'post_parent:' . (string) $id;
	}

	$cached_data = wp_cache_get_multiple( array_values( $cache_keys ), 'posts' );

	$non_cached_ids = array();
	foreach ( $cache_keys as $id => $cache_key ) {
		if ( false === $cached_data[ $cache_key ] ) {
			$non_cached_ids[] = $id;
		}
	}

	if ( ! empty( $non_cached_ids ) ) {
		$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );

		if ( $fresh_posts ) {
			$post_parent_data = array();
			foreach ( $fresh_posts as $fresh_post ) {
				$post_parent_data[ 'post_parent:' . (string) $fresh_post->ID ] = (int) $fresh_post->post_parent;
			}

			wp_cache_add_multiple( $post_parent_data, 'posts' );
		}
	}
}

常见问题

FAQs
查看更多 >