问题
I'm using this code to push data to a custom post type of a remote website:
$api_response = wp_remote_post( 'https://example.com/wp-json/wp/v2/clothing_line', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'admin:5mMcJGUGNFYq9PxU5P0ad0Np' )
),
'body' => array(
'title' => 'Pink Shirt',
'status' => 'publish',
'post_type' => 'clothes',
'categories' => 2,
'slug' => 'pink-shirt',
'meta' => array('amount' => '12.50', 'style' => 'petite', 'size' => 'small', 'gender' => 'ladies', 'author' => 1)
)
));
...and it works fine except for one issue.
'categories' => 2
will probably work fine for regular categories, but I have a custom taxonomy for it called 'clothing_line_cats'.
I need the post that is created on the remote site to have the category for the 'clothing_line_cats' taxonomy.
I tried adding this...
'taxonomy' => 'clothing_line_cats'
...but that did not work.
I can't find any documentation for achieving this.
回答1:
Feel kind of stupid I didn't realise this before.
Change this...
'categories' => 2
...to this...
'clothing_line_cats' => 2
来源:https://stackoverflow.com/questions/61199674/post-to-remote-wordpress-site-with-custom-taxonomy