acf_get_valid_terms

The Advanced Custom Fields acf get valid terms function.

Description

acf_get_valid_terms( (constant) $terms = false, (string) $taxonomy = 'category' ); 

This function will replace old terms with new split term ids

Parameters (2)

0. $terms — Optional. (constant) => false
The terms.
1. $taxonomy — Optional. (string) => 'category'
The taxonomy.

Usage

  1. if ( !function_exists( 'acf_get_valid_terms' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; 
  3.  
  4. // The terms. 
  5. $terms = false; 
  6.  
  7. // The taxonomy. 
  8. $taxonomy = 'category'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = acf_get_valid_terms($terms, $taxonomy); 
  12.  

Defined (1)

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

/core/api.php  
  1. function acf_get_valid_terms( $terms = false, $taxonomy = 'category' ) { 
  2.  
  3. // bail early if function does not yet exist or 
  4. if( !function_exists('wp_get_split_term') || empty($terms) ) { 
  5.  
  6. return $terms; 
  7.  
  8.  
  9.  
  10. // vars 
  11. $is_array = is_array($terms); 
  12.  
  13.  
  14. // force into array 
  15. $terms = acf_force_type_array( $terms ); 
  16.  
  17.  
  18. // force ints 
  19. $terms = array_map('intval', $terms); 
  20.  
  21.  
  22. // attempt to find new terms 
  23. foreach( $terms as $i => $term_id ) { 
  24.  
  25. $new_term_id = wp_get_split_term($term_id, $taxonomy); 
  26.  
  27. if( $new_term_id ) { 
  28.  
  29. $terms[ $i ] = $new_term_id; 
  30.  
  31.  
  32.  
  33.  
  34. // revert array if needed 
  35. if( !$is_array ) { 
  36.  
  37. $terms = $terms[0]; 
  38.  
  39.  
  40.  
  41. // return 
  42. return $terms; 
  43.