update_meta_cache [ WordPress Function ]
update_meta_cache ( $meta_type, $object_ids )
| Parameters: |
|
| Uses: |
|
| Returns: |
|
| Defined at: |
|
Soorgelijke functies: update_postmeta_cache, update_comment_cache, update_term_cache, update_page_cache, update_post_cache
Update the metadata cache for the specified objects.
Source
<?php
function update_meta_cache($meta_type, $object_ids) {
if ( empty( $meta_type ) || empty( $object_ids ) )
return false;
if ( ! $table = _get_meta_table($meta_type) )
return false;
$column = esc_sql($meta_type . '_id');
global $wpdb;
if ( !is_array($object_ids) ) {
$object_ids = preg_replace('|[^0-9,]|', '', $object_ids);
$object_ids = explode(',', $object_ids);
}
$object_ids = array_map('intval', $object_ids);
$cache_key = $meta_type . '_meta';
$ids = array();
$cache = array();
foreach ( $object_ids as $id ) {
$cached_object = wp_cache_get( $id, $cache_key );
if ( false === $cached_object )
$ids[] = $id;
else
$cache[$id] = $cached_object;
}
if ( empty( $ids ) )
return $cache;
// Get meta info
$id_list = join(',', $ids);
$meta_list = $wpdb->get_results( $wpdb->prepare("SELECT $column, meta_key, meta_value FROM $table WHERE $column IN ($id_list)",
$meta_type), ARRAY_A );
if ( !empty($meta_list) ) {
foreach ( $meta_list as $metarow) {
$mpid = intval($metarow[$column]);
$mkey = $metarow['meta_key'];
$mval = $metarow['meta_value'];
// Force subkeys to be array type:
if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) )
$cache[$mpid] = array();
if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) )
$cache[$mpid][$mkey] = array();
// Add a value to the current pid/key:
$cache[$mpid][$mkey][] = $mval;
}
}
foreach ( $ids as $id ) {
if ( ! isset($cache[$id]) )
$cache[$id] = array();
wp_cache_add( $id, $cache[$id], $cache_key );
}
return $cache;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- WordPress › Support » Add order by meta_id to update_meta_cache
Add order by meta_id to update_meta_cache (1 post). donatien. Member Posted 1 year ago #. As of now get_post_meta returns value pairs in random order ...
wordpress.org - WordPress › Support » Tags — update_meta_cache
Register · WordPress › Support » update_meta_cache. Tag: update_meta_cache Add New » ... Add order by meta_id to update_meta_cache, 1, donatien, 1 year ...
wordpress.org - PHPXRef 0.7 : WordPress : Function Reference: update_meta_cache()
Function and Method Cross Reference. update_meta_cache(). Defined at: /wp- includes/meta.php -> line 514. Referenced 5 times: /wp-includes/pluggable.php ...
phpxref.ftwr.co.uk - Reducing postmeta queries with update_meta_cache() | A ...
Reducing postmeta queries with update_meta_cache(). November 1, 2011 by Thorsten 0 Comments. Various themes and plugins make heavy use of postmeta ...
hitchhackerguide.com