• I realise this is possibly because I’m misunderstanding something, so hopefully someone can enlighten me.

    The documentation (http://codex.wordpress.org/Function_Reference/wp_set_object_terms) suggests that the function:

    `wp_set_object_terms( $object_id, $terms, $taxonomy, $append )

    takes a term ID or slug from an already inserted term (or an array of term IDs or slugs) as the $terms argument. However, upon using the function, and then reviewing the source code for it, it appears that it actually takes a raw term (e.g. “Strawberry” or “Ice Cream”), then does the check for the term and inserts it if it doesn’t exist.

    This means that if you pass it an ID or a slug, as instructed, it will create a new category (named, for instance, “2” or “ice-cream”) instead of simply relating the post to the term you intended.

    So, am I reading the Codex wrong, or is there an error in the documentation?

    [edit] apologies, should have put this in the hacks sub-forum instead…

Viewing 1 replies (of 1 total)
  • Use inval() in single term ID or array_map() in terms array:

    $terms = array_map('intval', $terms);
    //or $terms = intval($terms);
    wp_set_object_terms( '42', $terms, 'category' );
Viewing 1 replies (of 1 total)
  • The topic ‘wp_set_object_terms doesn't seem to work as described in the Codex’ is closed to new replies.