WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp update term

Contents

Description

Update term based on arguments provided.

Usage

<?php wp_update_term$term_id$taxonomy$args )  ?>

Parameters

$term_id
(int) (required) The ID of the term.
Default: None
$taxonomy
(string) (required) The context in which to relate the term to the object.
Default: None
$args
(array) (optional) Overwrite term field values.
Default: None

Return Values

(array|WP_Error) 
Returns Term ID and Taxonomy Term ID (in an array). Or an WP_Error object.

Example

Rename the 'Uncategorized' category in french

<?php
wp_update_term(1, 'category', array(
  'name' => 'Non Catégorisé',
  'slug' => 'non-categorise'
));
?>

Notes

The $args will indiscriminately override all values with the same field name. Care must be taken to not override important information need to update or update will fail (or perhaps create a new term, neither would be acceptable).

Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not defined in $args already.

'alias_of' will create a term group, if it doesn't already exist, and update it for the $term.

If the 'slug' argument in $args is missing, then the 'name' in $args will be used. It should also be noted that if you set 'slug' and it isn't unique then a WP_Error will be passed back. If you don't pass any slug, then a unique one will be created for you.

For what can be overrode in $args, check the term scheme can contain and stay away from the term keys.

Allowed $args for the term object:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count

Change Log

Since: 2.3.0

Source File

wp_update_term() is located in wp-includes/taxonomy.php.

Related

wp_insert_term

See also index of Function Reference and index of Template Tags.