I'm using the built-in WP REST API to create posts (custom post type). I've got this part working, below is some example JSON I submit to create a new post.
{
"title": "The story of Dr Foo",
"content": "This is the story content",
"status":"publish",
"excerpt":"Dr Foo story"
}
Problem is, how do I also pass which taxonomies to assign? I can't seem to find a trace of anyone asking or how to do it?
For context, server 1
is creating the posts and WP exists on server 2
.
I have also tried passing a long meta data with the request, to which I can then loop over on the WP server and set the taxonomies accordingly with wp_set_post_terms().
To do that, there is this (almost) rest_insert_{$this->post_type} that fires after a single post is created or updated via the REST API.
The problem with this method is that the meta data is not set until AFTER the action_rest_insert_post_type()
function has finished. This means that when I try to retrieve the current posts metadata, it doesn't exist.
function action_rest_insert_post_type( $post, $request, $true ) {
$items = get_post_meta( $post->ID); // at this point in time, returns empty array.
//wp_set_terms()
}
I have confirmed that $post->ID
is working as expected, it's just that the metadata isn't set fully...
Please advise.