1729 | | $tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
1730 | | $in_tt_ids = "'" . implode("', '", $tt_ids) . "'"; |
1731 | | do_action( 'delete_term_relationships', $object_id, $tt_ids ); |
1732 | | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id) ); |
1733 | | do_action( 'deleted_term_relationships', $object_id, $tt_ids ); |
1734 | | wp_update_term_count($tt_ids, $taxonomy); |
| 1727 | $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) ); |
| 1728 | $term_ids = array_map( 'intval', $term_ids ); |
| 1729 | wp_remove_object_terms( $object_id, $term_ids, $taxonomy ); |
2218 | | $delete_terms = array_diff($old_tt_ids, $tt_ids); |
2219 | | if ( $delete_terms ) { |
2220 | | $in_delete_terms = "'" . implode("', '", $delete_terms) . "'"; |
2221 | | do_action( 'delete_term_relationships', $object_id, $delete_terms ); |
2222 | | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_delete_terms)", $object_id) ); |
2223 | | do_action( 'deleted_term_relationships', $object_id, $delete_terms ); |
2224 | | wp_update_term_count($delete_terms, $taxonomy); |
| 2213 | $delete_tt_ids = array_diff( $old_tt_ids, $tt_ids ); |
| 2214 | |
| 2215 | if ( $delete_tt_ids ) { |
| 2216 | $in_delete_tt_ids = "'" . implode( "', '", $delete_tt_ids ) . "'"; |
| 2217 | $delete_term_ids = $wpdb->get_col( $wpdb->prepare( "SELECT tt.term_id FROM $wpdb->term_taxonomy AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ($in_delete_tt_ids)", $taxonomy ) ); |
| 2218 | $delete_term_ids = array_map( 'intval', $delete_term_ids ); |
| 2219 | |
| 2220 | $remove = wp_remove_object_terms( $object_id, $delete_term_ids, $taxonomy ); |
| 2221 | if ( is_wp_error( $remove ) ) { |
| 2222 | return $remove; |
| 2223 | } |
| 2247 | * Remove term(s) associated with a given object. |
| 2248 | * |
| 2249 | * @package WordPress |
| 2250 | * @subpackage Taxonomy |
| 2251 | * @since 3.6 |
| 2252 | * @uses $wpdb |
| 2253 | * |
| 2254 | * @uses apply_filters() Calls 'delete_term_relationships' hook with object_id and tt_ids as parameters. |
| 2255 | * @uses apply_filters() Calls 'deleted_term_relationships' hook with object_id and tt_ids as parameters. |
| 2256 | * |
| 2257 | * @param int $object_id The ID of the object from which to remove the terms. |
| 2258 | * @param array|int|string $terms The slug(s) or ID(s) of the term(s) to remove. |
| 2259 | * @param array|string $taxonomy Taxonomy name. |
| 2260 | * @return bool|WP_Error True on success, false or WP_Error on failure. |
| 2261 | */ |
| 2262 | function wp_remove_object_terms( $object_id, $terms, $taxonomy ) { |
| 2263 | global $wpdb; |
| 2264 | |
| 2265 | $object_id = (int) $object_id; |
| 2266 | |
| 2267 | if ( ! taxonomy_exists( $taxonomy ) ) { |
| 2268 | return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); |
| 2269 | } |
| 2270 | |
| 2271 | if ( ! is_array( $terms ) ) { |
| 2272 | $terms = array( $terms ); |
| 2273 | } |
| 2274 | |
| 2275 | $tt_ids = array(); |
| 2276 | |
| 2277 | foreach ( (array) $terms as $term ) { |
| 2278 | if ( ! strlen( trim( $term ) ) ) { |
| 2279 | continue; |
| 2280 | } |
| 2281 | |
| 2282 | if ( ! $term_info = term_exists( $term, $taxonomy ) ) { |
| 2283 | // Skip if a non-existent term ID is passed. |
| 2284 | if ( is_int( $term ) ) { |
| 2285 | continue; |
| 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | if ( is_wp_error( $term_info ) ) { |
| 2290 | return $term_info; |
| 2291 | } |
| 2292 | |
| 2293 | $tt_ids[] = $term_info['term_taxonomy_id']; |
| 2294 | } |
| 2295 | |
| 2296 | if ( $tt_ids ) { |
| 2297 | $in_tt_ids = "'" . implode( "', '", $tt_ids ) . "'"; |
| 2298 | do_action( 'delete_term_relationships', $object_id, $tt_ids ); |
| 2299 | $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id ) ); |
| 2300 | do_action( 'deleted_term_relationships', $object_id, $tt_ids ); |
| 2301 | wp_update_term_count( $tt_ids, $taxonomy ); |
| 2302 | |
| 2303 | return true; |
| 2304 | } |
| 2305 | |
| 2306 | return false; |
| 2307 | } |
| 2308 | |
| 2309 | /** |