I am sending posts with wordpress rest api. But I can’t send meta description. where did i go wrong.
wp_api_url = "https://xxxxx.com/wp-json/wp/v2/posts"
wp_auth_token = "xxxxxxx"
import requests
meta = {
"description": "test description",
"keywords": "test keywords",
"tags": "test Tag"
}
data = {
"title": conttitle,
"content": contcontent,
"status": "publish",
"data": {"filter": "raw", "meta": meta}
}
# Set headers for WordPress REST API request
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {wp_auth_token}",
}
response = requests.post(wp_api_url, headers=headers, json=data)
2
Answers
The arguments available to create a core WordPress Post are listed here. The argument
data
is not listed there (and may not be valid).meta
andtags
are top level arguments.meta
is not a property ofdata
.tags
(Post tags) is not a property ofmeta
.Try rearranging the json payload as follows:
json payload
filter
***The filter value might not apply to your case. You could be thinking of the ‘context’ argument used when sanitizing Posts.
custom post type
If trying to save meta data for a custom post type, please see the answer to this question: how to create a post having a custom field meta value via the WP REST API.
Use the Rest API wp/v2/posts/{id} endpoint with the below data:
This will update the post meta description. also check https://developer.wordpress.org/rest-api/reference/posts/#create-a-post