Support » Fixing WordPress » Setting multiple object terms

  • Code Metic


    Whats wrong with this? In setting multiple object terms.

    foreach($_POST['status'] as $status) {
        wp_set_object_terms($post_id, $status, 'status', true);
Viewing 2 replies - 1 through 2 (of 2 total)
  • This is pretty clear in the Codes page for wp_set_object_terms().

    Under ‘Parameters’, look at what it says for $terms:

    will replace all existing related terms in this taxonomy

    So, when you call that function over and over in the loop, you are over-writing all of the terms each time so you’ll only ever get the last one saved.

    To get around this, get the terms into an array before you set them. But seeing as how you already have them from $_POST you don’t need to worry about that.

    wp_set_object_terms($post_id, $_POST['status'], 'status');

    Of course, you also need to ensure that your stauts values are being sent as an array of terms, and not just a single term.

    Code Metic


    Still does not work.

    What i want that all in $_POST[‘status’] will be connected with term ‘status’.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Setting multiple object terms’ is closed to new replies.