Title: Function to insert post into a category.
Last modified: August 19, 2016

---

# Function to insert post into a category.

 *  Resolved [fatalx](https://wordpress.org/support/users/fatalx/)
 * (@fatalx)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/function-to-insert-post-into-a-category/)
 * Hello,
 * I was wondering if there is a function that will add a post (via post id) into
   specific categories (custom taxonomies in my case). I have been looking around
   for the function that does it but could not find it.
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [fatalx](https://wordpress.org/support/users/fatalx/)
 * (@fatalx)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/function-to-insert-post-into-a-category/#post-1778963)
 * I figured out my problem. I found this function
 *  `wp_set_object_terms`
 * it’s used this way
 *  `wp_set_object_terms($postid,$cat_ids,$taxonomy);`
 * $cat_ids has to be an array even if it’s only one element, and you have to make
   sure that all the ids are integers.
 * Hope this helps someone else.
 *  [Bofyx](https://wordpress.org/support/users/bofyx/)
 * (@bofyx)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/function-to-insert-post-into-a-category/#post-1779304)
 * Very helpful for me!
 * I am working on my website ([http://post.qp-x.com/](http://post.qp-x.com/)) and
   I didn’t know how to insert a category, but now everything works fine.
 * Thank you, fatalx!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Function to insert post into a category.’ is closed to new replies.

## Tags

 * [add](https://wordpress.org/support/topic-tag/add/)
 * [category](https://wordpress.org/support/topic-tag/category/)
 * [into](https://wordpress.org/support/topic-tag/into/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Bofyx](https://wordpress.org/support/users/bofyx/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/function-to-insert-post-into-a-category/#post-1779304)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
