Codex tools: Log in
Set categories for a post.
<?php wp_set_post_categories( $post_ID, $post_categories ) ?>
If no categories are passed with a post ID that has a post type of post, the default category will be used.
Be careful, as wp_set_post_categories will overwrite any existing categories already assigned to the post. You must include previously attached categories to the $post_categories parameter.
If an ID is passed with the categories array that is not associated with a valid category, it will be stripped before the object terms are updated and from the return array.
wp_set_object_terms() performs the same function with more granular control for built in categories and can also be used to set any custom taxonomies.
wp_set_post_categories() is located in