Home > database >  Unset post term in Wordpress
Unset post term in Wordpress

Time:03-09

I use this to set post terms from a custom taxonomy 'mois':

wp_set_post_terms(  $post_id, array ($term_id['term_id']), 'mois' ,true);

It works fine, but how coul i do the inverse : unset a post term ? I don't want to delete the term but only unset it from the post.

CodePudding user response:

Here is the solution for your question. You can just use wp_remove_object_terms hook to unset the terms using post id.

Here is the example of how you can do it:

$tag = array( 5 ); // Array of terms to be unset.

wp_remove_object_terms( $post_id, $tag, 'mois' );

  • Related