wp_update_category

Aliases wp_insert_category() with minimal args.

Description

(int|bool) wp_update_category( (array) $catarr ); 

If you want to update only some fields of an existing category, call this function with only the new values set inside $catarr.

Returns (int|bool)

The ID number of the new or updated Category on success. Zero or FALSE on failure.

Parameters (1)

0. $catarr — Optional. (array)
The cat_ID value is required. All other keys are optional.

Usage

  1. if ( !function_exists( 'wp_update_category' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; 
  3.  
  4. // The 'cat_ID' value is required. All other keys are optional. 
  5. $catarr = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_update_category($catarr); 
  9.  

Defined (1)

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

/wp-admin/includes/taxonomy.php  
  1. function wp_update_category($catarr) { 
  2. $cat_ID = (int) $catarr['cat_ID']; 
  3.  
  4. if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) ) 
  5. return false; 
  6.  
  7. // First, get all of the original fields 
  8. $category = get_term( $cat_ID, 'category', ARRAY_A ); 
  9. _make_cat_compat( $category ); 
  10.  
  11. // Escape data pulled from DB. 
  12. $category = wp_slash($category); 
  13.  
  14. // Merge old and new fields with new fields overwriting old ones. 
  15. $catarr = array_merge($category, $catarr); 
  16.  
  17. return wp_insert_category($catarr);