Since no direct function is there to achieve the required so I have made the code.
Code is self explanatory and you can tweak it the way you like.
<?php
//Assuming a post ID to reset tags.
$postid = 172;
//Assuming tag2 is supposed to be removed
$remove_tag = 'tag2';
//Collecting all the tags of post
$total_tags = get_the_tags($postid);
//Recreating an array without the $remove_tag
foreach($total_tags as $tag){
if($tag->name != $remove_tag){
$updated_tags[] = $tag->name;
}
}
//Setting tags with $updated_tags array.
wp_set_post_terms( $postid, $updated_tags, 'post_tag', false);
?>
If you are working on multiple posts then you can run a foreach
loop and by passing postid
in each loop.
EDIT
Code updated to include many posts (post id’s)
<?php
//Assuming a post ID to reset tags.
$posts_to_remove_tag_from = array(172,168);
//Assuming tag2 is supposed to be removed
$remove_tag = 'tag2';
//Collecting all the tags of post
foreach($posts_to_remove_tag_from as $postid){
$total_tags = get_the_tags($postid);
//Recreating an array to without the $remove_tag
foreach($total_tags as $tag){
if($tag->name != $remove_tag){
$updated_tags[] = $tag->name;
}
}
//Setting tags with $updated_tags array.
wp_set_post_terms( $postid, $updated_tags, 'post_tag', false);
//flushing $updated_tags array, and make it ready for next post in the loop.
$updated_tags = [];
}
?>