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!
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"
}
}
]
}
}
Try this:
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');
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
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).
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