Skip to content

Add a Category or Tag to a post programatically

$post_id = 1;
 
// Adding category to the post
$category_ids = array(4, 5, 6);
wp_set_object_terms( $post_id, $category_ids, 'category');
 
// Adding tags to the post
$tag_ids = array(7, 8, 9);
wp_set_object_terms( $post_id, $tag_ids, 'post_tag');

Categories: .

Comment Feed

2 Responses

  1. Whats the filter or action to call this?

    • It can be added anywhere after the core API (taxonomy functions) is loaded. Not sure if you were asking for this.

      Utkarsh KukretiAugust 10, 2010 @ 11:33 pmReply



Some HTML is OK

or, reply to this post via trackback.