On this page
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.
Parameters
$object_idint Required-
The term object ID that refers to the term.
$taxonomiesstring|array Required-
List of taxonomy names or single taxonomy name.
Source
File: wp-includes/taxonomy.php. View all references
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 );
}
}
Related
Uses
| Uses | Description |
|---|---|
| wp_get_object_terms() wp-includes/taxonomy.php | Retrieves the terms associated with the given object(s), in the supplied taxonomies. |
| wp_remove_object_terms() wp-includes/taxonomy.php | Removes term(s) associated with a given object. |
Used By
| Used By | Description |
|---|---|
| wp_delete_link() wp-admin/includes/bookmark.php | Deletes a specified link from the database. |
| wp_delete_attachment() wp-includes/post.php | Trashes or deletes an attachment. |
| wp_delete_post() wp-includes/post.php | Trashes or deletes a post or page. |
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_delete_object_term_relationships