gpt4 book ai didi

json - 具有自定义分类法的 WP-API 自定义帖子类型

转载 作者:行者123 更新时间:2023-12-05 01:03:20 25 4
gpt4 key购买 nike

我在和 https://github.com/WP-API/WP-API 打架我正在尝试使用名为 listing_categy 的自定义分类法添加自定义帖子类型:
查询这个端点:

http://example.com/subfolder/wp-json/taxonomies/listing_categy/terms

给我这个:

[
{
"ID": 9,
"name": "buying",
"slug": "buying-2",
"description": "",
"parent": null,
"count": 1,
"link": "http:\/\/example.com\/subfolder\/listing_categy\/buying-2\/",
"meta": {
"links": {
"collection": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms",
"self": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms\/7"
}
}
},
{
"ID": 10,
"name": "selling",
"slug": "selling-2",
"description": "",
"parent": null,
"count": 0,
"link": "http:\/\/example.com\/subfolder\/listing_categy\/selling-2\/",
"meta": {
"links": {
"collection": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms",
"self": "http:\/\/example.com\/subfolder\/wp-json\/taxonomies\/listing_categy\/terms\/8"
}
}
}
]

处理发帖的php文件是这个 https://github.com/WP-API/WP-API/blob/master/lib/class-wp-json-posts.php :
  /**
* Create a new post for any registered post type.
*
* @since 3.4.0
* @internal 'data' is used here rather than 'content', as get_default_post_to_edit uses $_REQUEST['content']
*
* @param array $content Content data. Can contain:
* - post_type (default: 'post')
* - post_status (default: 'draft')
* - post_title
* - post_author
* - post_excerpt
* - post_content
* - post_date_gmt | post_date
* - post_format
* - post_password
* - comment_status - can be 'open' | 'closed'
* - ping_status - can be 'open' | 'closed'
* - sticky
* - post_thumbnail - ID of a media item to use as the post thumbnail/featured image
* - custom_fields - array, with each element containing 'key' and 'value'
* - terms - array, with taxonomy names as keys and arrays of term IDs as values
* - terms_names - array, with taxonomy names as keys and arrays of term names as values
* - enclosure
* - any other fields supported by wp_insert_post()
* @return array Post data (see {@see WP_JSON_Posts::get_post})
*/
public function new_post( $data ) {
unset( $data['ID'] );

$result = $this->insert_post( $data );
if ( $result instanceof WP_Error ) {
return $result;
}

$response = json_ensure_response( $this->get_post( $result ) );
$response->set_status( 201 );
$response->header( 'Location', json_url( '/posts/' . $result ) );

return $response;
}

我已经尝试将 json 发送到/posts 并且它适用于所有条款......

我已经尝试了以下所有方法:
这个:
"title": $scope.listobject.listname, "status": "publish", "slug": "selling","type": "listing", "post_meta": $scope.dataform, "terms": { "listing_categy": [9] }

这个:
"title": $scope.listobject.listname, "status": "publish", "slug": "selling","type": "listing", "post_meta": $scope.dataform, "terms": { "listing_categy": [ {"ID": 9 } ]} 

这个:
"title": $scope.listobject.listname, "status": "publish", "slug": "selling","type": "listing", "post_meta": $scope.dataform, "terms": { "listing_categy": [9, 10 ] } 

这个:
"terms_names": { "listing_categy": ["selling", "buying"] } 

文档很糟糕

最佳答案

试试这个:
[your-site-root-dev-domain]/wp-json/posts/?type=[type-of-your-post]&filter[cat]=35

请看一看:
https://github.com/WP-API/WP-API/issues/343

告诉我这是否对你有帮助。

关于json - 具有自定义分类法的 WP-API 自定义帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24833940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com