Post to remote WordPress site with custom taxonomy

倾然丶 夕夏残阳落幕 提交于 2020-05-17 07:54:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!