wp_delete_object_term_relationships() WordPress Function

The wp_delete_object_term_relationships() function is used to delete all relationships between the given object and any terms in the given taxonomy. This function does not delete the terms themselves, only the relationships between the object and the terms.

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

Unlinks 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.


Top ↑

Parameters

$object_id

(int)(Required)The term object ID that refers to the term.

$taxonomies

(string|array)(Required)List of taxonomy names or single taxonomy name.


Top ↑

Source

File: 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 );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.3.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.

Show More
Show More