_wc_get_cached_product_terms

Cached version of wp_get_post_terms().

Description

(array) _wc_get_cached_product_terms( (int) $product_id, (string) $taxonomy, (array) $args = array() ); 

This is a private function (internal use ONLY).

Returns (array)

Parameters (3)

0. $product_id (int)
The product id.
1. $taxonomy (string)
Taxonomy slug.
2. $args — Optional. (array) => array()
Query arguments.

Usage

  1. if ( !function_exists( '_wc_get_cached_product_terms' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-term-functions.php'; 
  3.  
  4. // The product id. 
  5. $product_id = -1; 
  6.  
  7. // Taxonomy slug. 
  8. $taxonomy = ''; 
  9.  
  10. // Query arguments. 
  11. $args = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _wc_get_cached_product_terms($product_id, $taxonomy, $args); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-term-functions.php  
  1. function _wc_get_cached_product_terms( $product_id, $taxonomy, $args = array() ) { 
  2. $cache_key = 'wc_' . $taxonomy . md5( json_encode( $args ) ); 
  3. $terms = wp_cache_get( $product_id, $cache_key ); 
  4.  
  5. if ( false !== $terms ) { 
  6. return $terms; 
  7.  
  8. // @codingStandardsIgnoreStart 
  9. $terms = wp_get_post_terms( $product_id, $taxonomy, $args ); 
  10. // @codingStandardsIgnoreEnd 
  11.  
  12. wp_cache_add( $product_id, $terms, $cache_key ); 
  13.  
  14. return $terms;