update_meta_cache

The timeline below displays how wordpress function update_meta_cache has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Updates the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for.
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Short-circuits updating the metadata cache of a specific type.
     *
     * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * Possible hook names include:
     *
     *  - `update_post_metadata_cache`
     *  - `update_comment_metadata_cache`
     *  - `update_term_metadata_cache`
     *  - `update_user_metadata_cache`
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param int[] $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $cache_key = $meta_type . '_meta';
    $non_cached_ids = array();
    $cache = array();
    $cache_values = wp_cache_get_multiple($object_ids, $cache_key);
    foreach ($cache_values as $id => $cached_object) {
        if (false === $cached_object) {
            $non_cached_ids[] = $id;
        } else {
            $cache[$id] = $cached_object;
        }
    }
    if (empty($non_cached_ids)) {
        return $cache;
    }
    // Get meta info.
    $id_list = implode(',', $non_cached_ids);
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", ARRAY_A);
    if (!empty($meta_list)) {
        foreach ($meta_list as $metarow) {
            $mpid = (int) $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;
        }
    }
    $data = array();
    foreach ($non_cached_ids as $id) {
        if (!isset($cache[$id])) {
            $cache[$id] = array();
        }
        $data[$id] = $cache[$id];
    }
    wp_cache_add_multiple($data, $cache_key);
    return $cache;
}

WordPress Version: 5.9

/**
 * Updates the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for.
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Short-circuits updating the metadata cache of a specific type.
     *
     * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * Possible hook names include:
     *
     *  - `update_post_metadata_cache`
     *  - `update_comment_metadata_cache`
     *  - `update_term_metadata_cache`
     *  - `update_user_metadata_cache`
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param int[] $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $cache_key = $meta_type . '_meta';
    $non_cached_ids = array();
    $cache = array();
    $cache_values = wp_cache_get_multiple($object_ids, $cache_key);
    foreach ($cache_values as $id => $cached_object) {
        if (false === $cached_object) {
            $non_cached_ids[] = $id;
        } else {
            $cache[$id] = $cached_object;
        }
    }
    if (empty($non_cached_ids)) {
        return $cache;
    }
    // Get meta info.
    $id_list = implode(',', $non_cached_ids);
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", ARRAY_A);
    if (!empty($meta_list)) {
        foreach ($meta_list as $metarow) {
            $mpid = (int) $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 ($non_cached_ids as $id) {
        if (!isset($cache[$id])) {
            $cache[$id] = array();
        }
        wp_cache_add($id, $cache[$id], $cache_key);
    }
    return $cache;
}

WordPress Version: 5.6

/**
 * Updates the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for.
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Short-circuits updating the metadata cache of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param int[] $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $cache_key = $meta_type . '_meta';
    $non_cached_ids = array();
    $cache = array();
    $cache_values = wp_cache_get_multiple($object_ids, $cache_key);
    foreach ($cache_values as $id => $cached_object) {
        if (false === $cached_object) {
            $non_cached_ids[] = $id;
        } else {
            $cache[$id] = $cached_object;
        }
    }
    if (empty($non_cached_ids)) {
        return $cache;
    }
    // Get meta info.
    $id_list = implode(',', $non_cached_ids);
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", ARRAY_A);
    if (!empty($meta_list)) {
        foreach ($meta_list as $metarow) {
            $mpid = (int) $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 ($non_cached_ids as $id) {
        if (!isset($cache[$id])) {
            $cache[$id] = array();
        }
        wp_cache_add($id, $cache[$id], $cache_key);
    }
    return $cache;
}

WordPress Version: 5.5

/**
 * Updates the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for.
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Short-circuits updating the metadata cache of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param int[] $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $cache_key = $meta_type . '_meta';
    $non_cached_ids = array();
    $cache = array();
    $cache_values = wp_cache_get_multiple($object_ids, $cache_key);
    foreach ($cache_values as $id => $cached_object) {
        if (false === $cached_object) {
            $non_cached_ids[] = $id;
        } else {
            $cache[$id] = $cached_object;
        }
    }
    if (empty($non_cached_ids)) {
        return $cache;
    }
    // Get meta info.
    $id_list = join(',', $non_cached_ids);
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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 ($non_cached_ids as $id) {
        if (!isset($cache[$id])) {
            $cache[$id] = array();
        }
        wp_cache_add($id, $cache[$id], $cache_key);
    }
    return $cache;
}

WordPress Version: 5.4

/**
 * Updates the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for.
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Filters whether to update the metadata cache of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param int[] $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 5.3

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param string|int[] $object_ids Array or comma delimited list of object IDs to update cache for.
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Filters whether to update the metadata cache of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param int[] $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 5.0

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    /**
     * Filters whether to update the metadata cache of a specific type.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param mixed $check      Whether to allow updating the meta cache of the given type.
     * @param array $object_ids Array of object IDs to update the meta cache for.
     */
    $check = apply_filters("update_{$meta_type}_metadata_cache", null, $object_ids);
    if (null !== $check) {
        return (bool) $check;
    }
    $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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 9.9

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 9.3

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: .20

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 9.2

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: .10

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 4.3

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string    $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids Array or comma delimited list of object IDs to update cache for
 * @return array|false Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 4.1

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 4.0

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
function update_meta_cache($meta_type, $object_ids)
{
    global $wpdb;
    if (!$meta_type || !$object_ids) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 3.8

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
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 = sanitize_key($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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 7.5

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
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 = sanitize_key($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;
}

WordPress Version: .40

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
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 = sanitize_key($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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 7.4

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
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 = sanitize_key($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;
}

WordPress Version: .33

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
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 = sanitize_key($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);
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    $meta_list = $wpdb->get_results("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list}) ORDER BY {$id_column} ASC", 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;
}

WordPress Version: 3.7

/**
 * Update the metadata cache for the specified objects.
 *
 * @since 2.9.0
 * @uses $wpdb WordPress database object for queries.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int|array $object_ids array or comma delimited list of object IDs to update cache for
 * @return mixed Metadata cache for the specified objects, or false on failure.
 */
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 = sanitize_key($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;
}