wc_get_term_product_ids

Return products in a given term, and cache value.

Description

(array) wc_get_term_product_ids( (int) $term_id, (string) $taxonomy ); 

To keep in sync, product_count will be cleared on set_object_terms..

Returns (array)

Parameters (2)

0. $term_id (int)
The term id.
1. $taxonomy (string)
The taxonomy.

Usage

  1. if ( !function_exists( 'wc_get_term_product_ids' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-term-functions.php'; 
  3.  
  4. // The term id. 
  5. $term_id = -1; 
  6.  
  7. // The taxonomy. 
  8. $taxonomy = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_get_term_product_ids($term_id, $taxonomy); 
  12.  

Defined (1)

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

/includes/wc-term-functions.php  
  1. function wc_get_term_product_ids( $term_id, $taxonomy ) { 
  2. $product_ids = get_woocommerce_term_meta( $term_id, 'product_ids', true ); 
  3.  
  4. if ( false === $product_ids || ! is_array( $product_ids ) ) { 
  5. $product_ids = get_objects_in_term( $term_id, $taxonomy ); 
  6. update_woocommerce_term_meta( $term_id, 'product_ids', $product_ids ); 
  7.  
  8. return $product_ids;