add_post
This endpoint will allow you to add new posts. You can also add CPT by providing type var. Featured image can also be attached with the post.
Custom fields can be added via `update_post_meta` endpoint using post_id.
`nonce` requirement can be disabled from Settings > UserPlus. Admin notification for any new submitted posts can also be enabled/disabled from Settings > UserPlus.
Note: User must have capability to add post. Change user role if needed or allow from the Settings > UserPlus > options.
Screenshot with custom fields and feature image as file variable to the post:
Attach custom taxonomy to the post:
Resource URL
http://localhost/api/userplus/add_post/
Method
POST
Required Parameters
- cookie - for user authentication
- nonce - available from the get_nonce method (call with vars controller=userplus and method=new_post)
- status - sets the post status ("draft" or "publish")
- key – get API key from Settings > User Plus
Optional Parameters
- title - the post title
- content - the post content
- type – Post Type. Default is `post`.
- categories - a comma-separated list of categories (URL slugs)
- tags - a comma-separated list of tags (URL slugs)
- attachment – upload field will cause an attachment to be stored with new post with image set as featured thumbnail
- post_meta - associative array of meta_key and meta_value. Any number of pair are supported.
- taxonomy - Array keys of custom taxonomy type like this taxonomy[taxonomy_type] = comma separated ids of taxonomy, check screenshot
Sample Request URL
http://localhost/api/userplus/add_post/
Sample Response
{
"status": "ok",
"post": {
"id": 2016159605276693,
"type": "post",
"slug": "",
"url": "https://www.wppim.com/?p=2016159605276693",
"status": "draft",
"title": "New test Post with Post_meta & categories",
"title_plain": "New test Post with Post_meta & categories",
"content": "here is some content for test Post
\n",
"excerpt": "again updated content
\n",
"date": "2016-06-23 09:06:45",
"modified": "2020-08-27 19:03:57",
"categories": [
{
"id": 137,
"slug": "creativity",
"title": "Creativity",
"description": "",
"parent": 0,
"post_count": 4
},
{
"id": 40,
"slug": "technology",
"title": "Design",
"description": "",
"parent": 0,
"post_count": 3
},
{
"id": 47,
"slug": "lifestyle",
"title": "Lifestyle",
"description": "",
"parent": 0,
"post_count": 4
}
],
"tags": [],
"author": {
"id": 1,
"slug": "ali",
"name": "Ali",
"first_name": "Ali",
"last_name": "Qureshi",
"nickname": "Ali",
"url": "",
"description": "this is updated description, test"
},
"comments": [],
"attachments": [],
"comment_count": 0,
"comment_status": "closed",
"custom_fields": {}
},
"post_meta": {
"country": 117473,
"city": 117474,
"zipcode": 117475
}
}