使用自定义分类法发布到远程 WordPress 站点 [英] Post to remote WordPress site with custom taxonomy
问题描述
我正在使用此代码将数据推送到远程网站的自定义帖子类型:
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
可能适用于常规类别,但我有一个名为clothing_line_cats"的自定义分类法.
'categories' => 2
will probably work fine for regular categories, but I have a custom taxonomy for it called 'clothing_line_cats'.
我需要在远程站点上创建的帖子具有clothing_line_cats"分类法的类别.
I need the post that is created on the remote site to have the category for the 'clothing_line_cats' taxonomy.
我尝试添加这个...
'taxonomy' =>'clothing_line_cats'
...但这没有用.
我找不到实现此目的的任何文档.
I can't find any documentation for achieving this.
推荐答案
感觉有点愚蠢,我以前没有意识到这一点.
Feel kind of stupid I didn't realise this before.
改变这个...
'categories' =>2
...到这个...
'clothing_line_cats' =>2
这篇关于使用自定义分类法发布到远程 WordPress 站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!