Setting multiple object terms (3 posts)

  1. Code Metic
    Posted 3 years ago #

    Whats wrong with this? In setting multiple object terms.

    foreach($_POST['status'] as $status) {
        wp_set_object_terms($post_id, $status, 'status', true);
  2. michael.mariart
    Posted 3 years ago #

    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.

  3. Code Metic
    Posted 3 years ago #

    Still does not work.

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

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.