Title: Categorising a new Post
Last modified: August 21, 2016

---

# Categorising a new Post

 *  [richiemarshall](https://wordpress.org/support/users/richiemarshall/)
 * (@richiemarshall)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/categorising-a-new-post/)
 * Hi,
 * I’m able to create a new post using your getting started guide but the new posts
   are all uncategorized. I really need them to have categories assigned, and ideally
   tags too.
 * How do I achieve this? I’ve tried setting the category in the terms field on 
   the JSON payload but it doesn’t work for me.
 * example payload:
 *     ```
       {
           "title": "ldap-service 1.0.3 dev deploy",
           "status": "publish",
           "type": "post",
           "content": "Version 1.0.3 deployed to Dev servers by $user",
           "terms": {
             "category": [
               {
                 "name": "Dev",
                 "parent": {
                   "name": "Releases"
                 }
               }
             ]
           }
       }
       ```
   
 * Thanks for any help!
 * Rich
 * [https://wordpress.org/plugins/json-rest-api/](https://wordpress.org/plugins/json-rest-api/)

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

 *  Thread Starter [richiemarshall](https://wordpress.org/support/users/richiemarshall/)
 * (@richiemarshall)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4929922)
 * Correction, it appears that I have managed to create a post (i.e. the is a post
   ID, and a title which I can view) but the content of the post is missing too,
   along with the category. Can someone provide an example of posting a new article,
   and categorising it?
 * Thanks!
 *  Thread Starter [richiemarshall](https://wordpress.org/support/users/richiemarshall/)
 * (@richiemarshall)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4929943)
 * Progress!
 * The content element has to be defined as content_raw. Still no luck with categories
   though.
 *     ```
       {
           "title": "ldap-service 1.0.3 dev deploy",
           "status": "publish",
           "type": "post",
           "content_raw": "Version 1.0.3 deployed to Dev servers by $user",
           "terms": {
             "category": [
               {
                 "name": "Dev",
                 "parent": {
                   "name": "Releases"
                 }
               }
             ]
           }
       }
       ```
   
 *  [aryanduntley](https://wordpress.org/support/users/dunar21/)
 * (@dunar21)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4930095)
 * Try this:
 * [http://codex.wordpress.org/Function_Reference/wp_set_object_terms](http://codex.wordpress.org/Function_Reference/wp_set_object_terms)
 *     ```
       function assignTaxes($post, $data, $update){
         /*
          Here you would get the terms and taxes from the data var
          $data['my-terms'] $data['my-taxes']
          These would be set in the post params from the sending device
         */
         $terms = array("bluegroup","orangegroup","whitegroup");
         $taxonomy = ("category","custom-tax");
         $append = false; //true = add to, false = replace all existing
          wp_set_object_terms($post['ID'], $terms, $taxonomy, $append);
         //wp_set_object_terms($post['ID'], array_map( 'intval', $data['my-terms'] );, $data['my-taxes']);
         //check for wp error or string if offered wrong term
         //if(is_wp_error($term_taxonomy_ids)){}else{}
       }
   
       add_action( 'json_insert_post', 'assignTaxes');
       ```
   
 *  [Yoheri](https://wordpress.org/support/users/yoheri/)
 * (@yoheri)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4930131)
 * Hi aryanduntley,
 * i’m newbie in wordpress code, but have experience with PHP.
 * May i use this add_action (and function) in my own plugin, or i have to put it
   inside some file of the Json Rest Plugin?
 * Regards,
    Heriberto
 *  [aryanduntley](https://wordpress.org/support/users/dunar21/)
 * (@dunar21)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4930132)
 * You can use this in your functions.php file, or in your plugin file. It is simply
   a hook. In wordpress hooks can called from pretty much anywhere. Typically, someone
   would use it in their funcions.php file, or in their plugins main functions file(
   or called into their main functions file).
 *  [Yoheri](https://wordpress.org/support/users/yoheri/)
 * (@yoheri)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4930133)
 * Hi aryanduntley,
 * thanks for your fast reply !!! 😀
 * Ok, i’m going to use it in my own pluging. I think it’s more clean.
 * Regards,
    Heriberto

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

The topic ‘Categorising a new Post’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/json-rest-api_2e3641.svg)
 * [WP REST API (WP API)](https://wordpress.org/plugins/json-rest-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/json-rest-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/json-rest-api/)
 * [Active Topics](https://wordpress.org/support/plugin/json-rest-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/json-rest-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/json-rest-api/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [Yoheri](https://wordpress.org/support/users/yoheri/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/categorising-a-new-post/#post-4930133)
 * Status: not resolved