cptui_convert_taxonomy_terms

Convert taxonomies.

Description

cptui_convert_taxonomy_terms( (string) $original_slug = '', (string) $new_slug = '' ); 

Parameters (2)

0. $original_slug — Optional. (string) => ''
Original taxonomy slug. Optional. Default empty string.
1. $new_slug — Optional. (string) => ''
New taxonomy slug. Optional. Default empty string.

Usage

  1. if ( !function_exists( 'cptui_convert_taxonomy_terms' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/inc/taxonomies.php'; 
  3.  
  4. // Original taxonomy slug. Optional. Default empty string. 
  5. $original_slug = ''; 
  6.  
  7. // New taxonomy slug. Optional. Default empty string. 
  8. $new_slug = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = cptui_convert_taxonomy_terms($original_slug, $new_slug); 
  12.  

Defined (1)

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

/inc/taxonomies.php  
  1. function cptui_convert_taxonomy_terms( $original_slug = '', $new_slug = '' ) { 
  2. global $wpdb; 
  3.  
  4. $args = array( 
  5. 'taxonomy' => $original_slug,  
  6. 'hide_empty' => false,  
  7. 'fields' => 'ids',  
  8. ); 
  9.  
  10. $term_ids = get_terms( $args ); 
  11.  
  12. if ( is_int( $term_ids ) ) { 
  13. $term_ids = (array) $term_ids; 
  14.  
  15. if ( is_array( $term_ids ) && ! empty( $term_ids ) ) { 
  16. $term_ids = implode( ', ', $term_ids ); 
  17.  
  18. $query = "UPDATE `{$wpdb->term_taxonomy}` SET `taxonomy` = %s WHERE `taxonomy` = %s AND `term_id` IN ( {$term_ids} )"; 
  19.  
  20. $wpdb->query( 
  21. $wpdb->prepare( $query, $new_slug, $original_slug ) 
  22. ); 
  23. cptui_delete_taxonomy( $original_slug );