wp_update_category() WordPress Function

The wp_update_category() function is used to update an existing category in WordPress. The function takes two parameters: the category ID and an array of arguments. The array of arguments can include the following: - name: The new name for the category. - slug: The new slug for the category. - parent: The new parent category for the category. - description: The new description for the category. The function will return a WP_Error object on failure or true on success.

wp_update_category( array $catarr ) #

Aliases wp_insert_category() with minimal args.


Description

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


Top ↑

Parameters

$catarr

(array)(Required)The 'cat_ID' value is required. All other keys are optional.


Top ↑

Return

(int|false) The ID number of the new or updated Category on success. Zero or FALSE on failure.


Top ↑

Source

File: wp-admin/includes/taxonomy.php

function wp_update_category( $catarr ) {
	$cat_ID = (int) $catarr['cat_ID'];

	if ( isset( $catarr['category_parent'] ) && ( $cat_ID == $catarr['category_parent'] ) ) {
		return false;
	}

	// First, get all of the original fields.
	$category = get_term( $cat_ID, 'category', ARRAY_A );
	_make_cat_compat( $category );

	// Escape data pulled from DB.
	$category = wp_slash( $category );

	// Merge old and new fields with new fields overwriting old ones.
	$catarr = array_merge( $category, $catarr );

	return wp_insert_category( $catarr );
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.