_wp_check_split_terms_in_menus

Check menu items when a term gets split to see if any of them need to be updated.

Description

_wp_check_split_terms_in_menus( (int) $term_id, (int) $new_term_id, (int) $term_taxonomy_id, (string) $taxonomy ); 

Parameters (4)

0. $term_id (int)
ID of the formerly shared term.
1. $new_term_id (int)
ID of the new term created for the $term_taxonomy_id.
2. $term_taxonomy_id (int)
ID for the term_taxonomy row affected by the split.
3. $taxonomy (string)
Taxonomy for the split term.

Usage

  1. if ( !function_exists( '_wp_check_split_terms_in_menus' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // ID of the formerly shared term. 
  5. $term_id = -1; 
  6.  
  7. // ID of the new term created for the $term_taxonomy_id. 
  8. $new_term_id = -1; 
  9.  
  10. // ID for the term_taxonomy row affected by the split. 
  11. $term_taxonomy_id = -1; 
  12.  
  13. // Taxonomy for the split term. 
  14. $taxonomy = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = _wp_check_split_terms_in_menus($term_id, $new_term_id, $term_taxonomy_id, $taxonomy); 
  18.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { 
  2. global $wpdb; 
  3. $post_ids = $wpdb->get_col( $wpdb->prepare( 
  4. "SELECT m1.post_id 
  5. FROM {$wpdb->postmeta} AS m1 
  6. INNER JOIN {$wpdb->postmeta} AS m2 ON ( m2.post_id = m1.post_id ) 
  7. INNER JOIN {$wpdb->postmeta} AS m3 ON ( m3.post_id = m1.post_id ) 
  8. WHERE ( m1.meta_key = '_menu_item_type' AND m1.meta_value = 'taxonomy' ) 
  9. AND ( m2.meta_key = '_menu_item_object' AND m2.meta_value = '%s' ) 
  10. AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )",  
  11. $taxonomy,  
  12. $term_id 
  13. ) ); 
  14.  
  15. if ( $post_ids ) { 
  16. foreach ( $post_ids as $post_id ) { 
  17. update_post_meta( $post_id, '_menu_item_object_id', $new_term_id, $term_id );