Wordpress API: Add / Remove Tags on Posts

Posted by st4ck0v3rfl0w on Stack Overflow See other posts from Stack Overflow or by st4ck0v3rfl0w
Published on 2010-03-12T23:11:08Z Indexed on 2010/03/12 23:17 UTC
Read the original article Hit count: 251

I know it seems like a simple operation, but I can't find any resource or documentation that explains how to programmatically add and remove tags to a post using the post ID.

Below is a sample of what I'm using, but it seems to overwrite all the other tags...

function addTerm($id, $tax, $term) {

    $term_id = is_term($term);
    $term_id = intval($term_id);
    if (!$term_id) {
        $term_id = wp_insert_term($term, $tax);
        $term_id = $term_id['term_id'];
        $term_id = intval($term_id);
    }
    $result =  wp_set_object_terms($id, array($term_id), $tax, FALSE);

    return $result;
}

© Stack Overflow or respective owner

Related posts about wordpress-plugin-dev

Related posts about wordpress-plugin