WordPress.org

Forums

[resolved] Function to insert post into a category. (3 posts)

  1. fatalx
    Member
    Posted 4 years ago #

    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

  2. fatalx
    Member
    Posted 4 years ago #

    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.

  3. Bofyx
    Member
    Posted 4 years ago #

    Very helpful for me!

    I am working on my website (http://post.qp-x.com/) and I didn't know how to insert a category, but now everything works fine.

    Thank you, fatalx!

Topic Closed

This topic has been closed to new replies.

About this Topic