Why does this work to remove a single term?

$existingTerms = wp_get_post_terms($postID, 'custom_taxonomy');
        $newTerms = array();
        foreach($existingTerms as $term) {
            if ($term->slug != 'remove_this_term') {
                $newTerms[] = $term->term_id;
wp_set_post_terms($postID, $newTerms, 'custom_taxonomy');

But this doesn't?:

wp_remove_object_terms($postID, 'remove_this_term', 'custom_taxonomy');

Am I misunderstanding what wp_remove_object_terms does?

  • Should work as expected. Did you notice the two terms differ in the set and remove function? You added a s. So maybe you get early returned by wp_remove_object_terms. – Fabian Marz Apr 1 '18 at 8:19
  • That was just a test variable sorry. In my real code both are the same – Eckstein Apr 1 '18 at 13:47
  • 2
    If the term argument is a string it is interpreted as the term slug. Use integers for ids. – TheDeadMedic Apr 1 '18 at 16:39

I know this is old but I ran across this issue, adding true to the end of the hook resolved the issue. In this instance wp_remove_object_terms($postID, 'remove_this_term', 'custom_taxonomy', true); will run the hook.

  • It doesn't have a fourth parameter. I believe their term_id was a string, not integer. – Christine Cooper Dec 19 '20 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.