manoelcalixto
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [WordPress REST API (Version 2)] How to create a post with category?Thanks for the feedback , I am sending this way you went , but it is not working.
Follows the requested information:
categories:
[ { "id": ?1, "count": ?0, "description": "", "link": "https://localhost/wordpress/category/sem-categoria/", "name": "Sem categoria", "slug": "sem-categoria", "taxonomy": "category", "parent": ?0, "_links": { "self": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories/1" } ], "collection": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories" } ], "about": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/taxonomies/category" } ], "https://api.w.org/v2/post_type": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/posts?categories=1" } ] } }, { "id": ?2, "count": ?0, "description": "", "link": "https://localhost/wordpress/category/teste/", "name": "teste", "slug": "teste", "taxonomy": "category", "parent": ?0, "_links": { "self": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories/2" } ], "collection": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories" } ], "about": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/taxonomies/category" } ], "https://api.w.org/v2/post_type": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/posts?categories=2" } ] } }, { "id": ?3, "count": ?0, "description": "", "link": "https://localhost/wordpress/category/teste2/", "name": "teste2", "slug": "teste2", "taxonomy": "category", "parent": ?0, "_links": { "self": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories/3" } ], "collection": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories" } ], "about": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/taxonomies/category" } ], "https://api.w.org/v2/post_type": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/posts?categories=3" } ] } }, { "id": ?5, "count": ?0, "description": "", "link": "https://localhost/wordpress/category/teste3/", "name": "teste3", "slug": "teste3", "taxonomy": "category", "parent": ?0, "_links": { "self": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories/5" } ], "collection": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories" } ], "about": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/taxonomies/category" } ], "https://api.w.org/v2/post_type": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/posts?categories=5" } ] } }, { "id": ?4, "count": ?0, "description": "", "link": "https://localhost/wordpress/category/teste4/", "name": "teste4", "slug": "teste4", "taxonomy": "category", "parent": ?0, "_links": { "self": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories/4" } ], "collection": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/categories" } ], "about": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/taxonomies/category" } ], "https://api.w.org/v2/post_type": [ { "href": "https://localhost/wordpress/wp-json/wp/v2/posts?categories=4" } ] } } ]
Code request:
import requests from requests.auth import HTTPBasicAuth payload = {'title': 'teste', 'content': 'calixto', 'categories': [1, 2, 3, 4, 5]} r = requests.post('https://localhost/wordpress/wp-json/wp/v2/posts/', auth=HTTPBasicAuth('', ''), params=payload) print(r.text)
Response:
<br /> <b>Warning</b>: array_map(): Argument #2 should be an array in <b>/opt/lampp/htdocs/wordpress/wp-content/plugins/rest-api/lib/endpoints/class-wp-rest-posts-controller.php</b> on line <b>918</b><br />
{ "id":91, "date":"2016-02-26T03:36:10", "date_gmt":null, "guid":{ "rendered":"http:\/\/localhost\/wordpress\/?p=91", "raw":"http:\/\/localhost\/wordpress\/?p=91" }, "modified":"2016-02-26T03:36:10", "modified_gmt":null, "password":"", "slug":"", "status":"draft", "type":"post", "link":"http:\/\/localhost\/wordpress\/?p=91", "title":{ "raw":"teste", "rendered":"teste" }, "content":{ "raw":"calixto", "rendered":"<p>calixto<\/p>\n" }, "excerpt":{ "raw":"", "rendered":"<p>calixto<\/p>\n" }, "author":1, "featured_media":0, "comment_status":"open", "ping_status":"open", "sticky":false, "format":"standard", "categories":[ ], "tags":[ ], "_links":{ "self":[ { "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/posts\/91" } ], "collection":[ { "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/posts" } ], "about":[ { "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/types\/post" } ], "author":[ { "embeddable":true, "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/users\/1" } ], "replies":[ { "embeddable":true, "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/comments?post=91" } ], "version-history":[ { "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/posts\/91\/revisions" } ], "https:\/\/api.w.org\/attachment":[ { "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/media?parent=91" } ], "https:\/\/api.w.org\/term":[ { "taxonomy":"category", "embeddable":true, "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/categories?post=91" }, { "taxonomy":"post_tag", "embeddable":true, "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/tags?post=91" } ], "https:\/\/api.w.org\/meta":[ { "embeddable":true, "href":"http:\/\/localhost\/wordpress\/wp-json\/wp\/v2\/posts\/91\/meta" } ] } }
Viewing 1 replies (of 1 total)