get_object_term_cache( int $id, string $taxonomy )
Retourne les objets de termes du cache pour un id d'objet donné.
Paramètres
$id(int)requisId d'objet de terme. Par exemple, un id de publication, de commentaire ou d'un d'utilisateur.
$taxonomy(string)requisNom d'une taxonomie.
Description / Informations supplémentaires
Les fonctions en amont comme get_the_terms() et is_object_in_term() sont responsables de l'agrandissement des associations termes - objets en cache. Seule la fonction get_object_term_cache() retrouve les données d'associations qui existent déjà dans le cache.
Retourne
(bool|WP_Term[]|WP_Error) Un tableau d'objets WP_Term si mis en cache.
false si le cache est vide pour $taxonomy et $id.
L'objet WP_Error si get_term() renvoie un objet d'erreur pour n'importe quel terme.
Déclaration et structure de la fonction get_object_term_cache()
get_object_term_cache() est déclarée dans le fichier wp-includes/taxonomy.php à la ligne 3747 :
function get_object_term_cache( $id, $taxonomy ) {
$_term_ids = wp_cache_get( $id, "{$taxonomy}_relationships" );
// We leave the priming of relationship caches to upstream functions.
if ( false === $_term_ids ) {
return false;
}
// Backward compatibility for if a plugin is putting objects into the cache, rather than IDs.
$term_ids = array();
foreach ( $_term_ids as $term_id ) {
if ( is_numeric( $term_id ) ) {
$term_ids[] = (int) $term_id;
} elseif ( isset( $term_id->term_id ) ) {
$term_ids[] = (int) $term_id->term_id;
}
}
// Fill the term objects.
_prime_term_caches( $term_ids );
$terms = array();
foreach ( $term_ids as $term_id ) {
$term = get_term( $term_id, $taxonomy );
if ( is_wp_error( $term ) ) {
return $term;
}
$terms[] = $term;
}
return $terms;
}
Fonctions utilisées par get_object_term_cache()
_prime_term_caches()Ajoute tous les termes des ids donnés au cache qui n'existent pas déjà dans le cache.
wp_cache_get()Retourne les contenus du cache en donnant la clé et le groupe.
get_term()Retourne toutes les données d'un terme en donnant son ID.
is_wp_error()Vérifie si la variable est une erreur WordPress.
Où est utilisée la fonction get_object_term_cache()
dans le CMS WordPress
Sources
Codex WordPress : get_object_term_cache()
Autres fonctions dans le même fichier : wp-includes/taxonomy.php