get_metadata_raw( string $meta_type, int $object_id, string $meta_key = '', bool $single = false )
Retourne la valeur originale de la méta-donnée pour une clé de méta et un id d'objet spécifiés.
Paramètres
$meta_type
(string)requisType d'objet pour lequel la méta-donnée est retournée. Accepte 'post', 'comment', 'term', 'user' ou tout autre type d'objet associé à une table meta.
$object_id
(int)requisId de l'objet pour lequel la méta-donnée est retournée.
$meta_key
(string)optionnelClé de la méta-donnée. Si omise retourne les valeurs de toutes les métadonnée rattachées à l'objet spécifié.
Valeur par défaut : ''
$single
(bool)optionnelSi true, la valeur sera retournée simplement, si laissé à false, la valeur sera retournée dans un tableau. Si $key est omis ce réglage n'aura aucun effet.
Valeur par défaut : false
Retourne
(mixed) Valeur unique ou tableau de valeurs. Null si la valeur n'existe pas. False si s'il y a un problème avec les paramètres passés à la fonction.
Déclaration et structure de la fonction get_metadata_raw()
get_metadata_raw()
est déclarée dans le fichier wp-includes/meta.php
à la ligne 600 :
function get_metadata_raw( $meta_type, $object_id, $meta_key = '', $single = false ) {
if ( ! $meta_type || ! is_numeric( $object_id ) ) {
return false;
}
$object_id = absint( $object_id );
if ( ! $object_id ) {
return false;
}
/**
* Short-circuits the return value of a meta field.
*
* 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 filter names include:
*
* - `get_post_metadata`
* - `get_comment_metadata`
* - `get_term_metadata`
* - `get_user_metadata`
*
* @since 3.1.0
* @since 5.5.0 Added the `$meta_type` parameter.
*
* @param mixed $value The value to return, either a single metadata value or an array
* of values depending on the value of `$single`. Default null.
* @param int $object_id ID of the object metadata is for.
* @param string $meta_key Metadata key.
* @param bool $single Whether to return only the first value of the specified `$meta_key`.
* @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.
*/
$check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single, $meta_type );
if ( null !== $check ) {
if ( $single && is_array( $check ) ) {
return $check[0];
} else {
return $check;
}
}
$meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );
if ( ! $meta_cache ) {
$meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
if ( isset( $meta_cache[ $object_id ] ) ) {
$meta_cache = $meta_cache[ $object_id ];
} else {
$meta_cache = null;
}
}
if ( ! $meta_key ) {
return $meta_cache;
}
if ( isset( $meta_cache[ $meta_key ] ) ) {
if ( $single ) {
return maybe_unserialize( $meta_cache[ $meta_key ][0] );
} else {
return array_map( 'maybe_unserialize', $meta_cache[ $meta_key ] );
}
}
return null;
}
Fonctions utilisées par get_metadata_raw()
wp_cache_get()
Retourne le contenu du cache par clés et groupes.
absint()
Convertit une valeur en entier positif (valeur absolue).
maybe_unserialize()
Désérialize des données seulement si elles ont été sérializées au préalable.
apply_filters()
Appel les fonctions qui ont été attaché à un filtre (hook).
update_meta_cache()
Met à jour le cache d'une méta-donnée pour les objets spécifiés.
Hook utilisé par get_metadata_raw()
get_meta_type_metadata
Court-circuite la valeur du champ de méta retournée.
Où est utilisée la fonction get_metadata_raw()
dans le CMS WordPress
Sources
Codex WordPress : get_metadata_raw()
Autres fonctions dans le même fichier : wp-includes/meta.php