wp_delete_object_term_relationships
Will unlink the object from the taxonomy or taxonomies.
Description
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
if ( !function_exists( 'wp_delete_object_term_relationships' ) ) { require_once ABSPATH . WPINC . '/taxonomy.php'; } // The term Object Id that refers to the term. $object_id = -1; // List of Taxonomy Names or single Taxonomy name. $taxonomies = null; // NOTICE! Understand what this does before running. $result = wp_delete_object_term_relationships($object_id, $taxonomies);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/taxonomy.php
- function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
- $object_id = (int) $object_id;
- if ( !is_array($taxonomies) )
- $taxonomies = array($taxonomies);
- foreach ( (array) $taxonomies as $taxonomy ) {
- $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) );
- $term_ids = array_map( 'intval', $term_ids );
- wp_remove_object_terms( $object_id, $term_ids, $taxonomy );
- }
- }