使用自定义分类法发布到远程WordPress网站 [英] Post to remote WordPress site with custom taxonomy

查看:100
本文介绍了使用自定义分类法发布到远程WordPress网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将数据推送到远程网站的自定义帖子类型:

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.

我尝试添加此内容...

I tried adding this...

'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆