wp_remove_object_terms

The timeline below displays how wordpress function wp_remove_object_terms has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Removes term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param string           $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if ('' === trim($term)) {
            continue;
        }
        $term_info = term_exists($term, $taxonomy);
        if (!$term_info) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids, $taxonomy);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        wp_cache_set_terms_last_changed();
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids, $taxonomy);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 6.1

/**
 * Removes term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param string           $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if ('' === trim($term)) {
            continue;
        }
        $term_info = term_exists($term, $taxonomy);
        if (!$term_info) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids, $taxonomy);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        wp_cache_delete('last_changed', 'terms');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids, $taxonomy);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 5.9

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param string           $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if ('' === trim($term)) {
            continue;
        }
        $term_info = term_exists($term, $taxonomy);
        if (!$term_info) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids, $taxonomy);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        wp_cache_delete('last_changed', 'terms');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids, $taxonomy);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 5.3

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if ('' === trim($term)) {
            continue;
        }
        $term_info = term_exists($term, $taxonomy);
        if (!$term_info) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids, $taxonomy);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        wp_cache_delete('last_changed', 'terms');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids, $taxonomy);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.8

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param string|int|array $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids, $taxonomy);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        wp_cache_delete('last_changed', 'terms');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids, $taxonomy);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.7

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids, $taxonomy);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         * @since 4.7.0 Added the `$taxonomy` parameter.
         *
         * @param int    $object_id Object ID.
         * @param array  $tt_ids    An array of term taxonomy IDs.
         * @param string $taxonomy  Taxonomy slug.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids, $taxonomy);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.6

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy.'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.5

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.4

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_cache_delete($object_id, $taxonomy . '_relationships');
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.3

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int              $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms     The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string     $taxonomy  Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 4.1

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string $taxonomy Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 3.9

/**
 * Remove term(s) associated with a given object.
 *
 * @since 3.6.0
 * @uses $wpdb
 *
 * @param int $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string $taxonomy Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        /**
         * Fires immediately before an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        /**
         * Fires immediately after an object-term relationship is deleted.
         *
         * @since 2.9.0
         *
         * @param int   $object_id Object ID.
         * @param array $tt_ids    An array of term taxonomy IDs.
         */
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}

WordPress Version: 3.7

/**
 * Remove term(s) associated with a given object.
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 3.6
 * @uses $wpdb
 *
 * @uses apply_filters() Calls 'delete_term_relationships' hook with object_id and tt_ids as parameters.
 * @uses apply_filters() Calls 'deleted_term_relationships' hook with object_id and tt_ids as parameters.
 *
 * @param int $object_id The ID of the object from which the terms will be removed.
 * @param array|int|string $terms The slug(s) or ID(s) of the term(s) to remove.
 * @param array|string $taxonomy Taxonomy name.
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function wp_remove_object_terms($object_id, $terms, $taxonomy)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    $tt_ids = array();
    foreach ((array) $terms as $term) {
        if (!strlen(trim($term))) {
            continue;
        }
        if (!$term_info = term_exists($term, $taxonomy)) {
            // Skip if a non-existent term ID is passed.
            if (is_int($term)) {
                continue;
            }
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $tt_ids[] = $term_info['term_taxonomy_id'];
    }
    if ($tt_ids) {
        $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
        do_action('delete_term_relationships', $object_id, $tt_ids);
        $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        do_action('deleted_term_relationships', $object_id, $tt_ids);
        wp_update_term_count($tt_ids, $taxonomy);
        return (bool) $deleted;
    }
    return false;
}