wp_delete_object_term_relationships

Will unlink the object from the taxonomy or taxonomies.

Description

wp_delete_object_term_relationships( (int) $object_id, (string|array) $taxonomies ); 

Will remove all relationships between the object and any terms in a particular taxonomy or taxonomies. Does not remove the term or taxonomy itself.

Parameters (2)

0. $object_id (int)
The term Object Id that refers to the term.
1. $taxonomies (string|array)
List of Taxonomy Names or single Taxonomy name.

Usage

  1. if ( !function_exists( 'wp_delete_object_term_relationships' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // The term Object Id that refers to the term. 
  5. $object_id = -1; 
  6.  
  7. // List of Taxonomy Names or single Taxonomy name. 
  8. $taxonomies = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_delete_object_term_relationships($object_id, $taxonomies); 
  12.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function wp_delete_object_term_relationships( $object_id, $taxonomies ) { 
  2. $object_id = (int) $object_id; 
  3.  
  4. if ( !is_array($taxonomies) ) 
  5. $taxonomies = array($taxonomies); 
  6.  
  7. foreach ( (array) $taxonomies as $taxonomy ) { 
  8. $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) ); 
  9. $term_ids = array_map( 'intval', $term_ids ); 
  10. wp_remove_object_terms( $object_id, $term_ids, $taxonomy );