Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to figure out why wp_set_object terms will update the terms in a given taxonomy but when I set the $terms param to NULL it keeps one of the terms - the one with the lowest ID.

I've altered a plugin for frontend editing of posts - WP User FrontEnd.

Here's my wp_set_object_terms code coming from a set of check boxes in a form:

if( !empty($_POST['wpuf_tax_TAXONOMY']) ):
  $cat_ids = $_POST['wpuf_tax_TAXONOMY'];
  $cat_ids = array_map('intval', $cat_ids);
  $cat_ids = array_unique( $cat_ids );
  wp_set_object_terms( $post_id, $cat_ids, 'TAXONOMY' );
else:
  wp_set_object_terms( $post_id, NULL, 'TAXONOMY' );
endif;

Not sure what to do about this or why it won't delete the terms when none are selected in the form.

Any help is appreciated.

EDIT---------------------------------------------------------------

I have noticed that wp_set_object_terms does add and remove terms as expected. But I need to refresh the page after the form update to see the changes.

I tried a wp_redirect on successful submission but got a "headers already sent" error. Is there a way to reload the page with out having to refresh the page after the from updates? Hope that made sense.

share|improve this question

closed as too localized by toscho Jul 16 '12 at 23:28

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Redirect before any output. How are you processing your form anyway? –  onetrickpony Sep 28 '11 at 23:10
    
I just figured out the problem.... I had another function checking if the post had the current term, and it wasn't functioning properly. as soon as I altered the code, everything updated the first time through on the form. Even added all the meta data to the form no problem. Thanx –  dkmojo Sep 29 '11 at 19:47
    
@dkmojo Can you post your solution as an answer? After a day passes you can then accept it as the best answer so that it does not haunt the site as Unanswered. Thanks! –  Jared Mar 1 '12 at 3:28

1 Answer 1

I was passing $ostid instead of $postid into my function. As soon as I used the 'real' post id it solved my issue. Just a typo on my part.

share|improve this answer

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