wp_delete_object_term_relationships

函数
wp_delete_object_term_relationships ( $object_id, $taxonomies )
参数
  • (int) $object_id The term object ID that refers to the term.
    Required:
  • (string|array) $taxonomies List of taxonomy names or single taxonomy name.
    Required:
定义位置
相关方法
wp_get_object_termswp_set_object_termsupdate_object_term_cachewp_add_object_termswp_remove_object_terms
引入
2.3.0
弃用
-

wp_delete_object_term_relationships:此函数删除给定对象的所有术语关系。它将对象ID和分类名称作为参数,并从WordPress数据库中删除该对象和分类的所有术语关系。

从分类标准或分类标准中解除对象的链接。

将删除对象与特定分类法或分类法中任何术语之间的所有关系。并不删除术语或分类法本身。

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

常见问题

FAQs
查看更多 >