我正在尝试获取自定义帖子类型的类别,但无法找到任何解决方案。The WP REST API documentation只返回博客文章的类别。
自定义帖子接口:https://themographics.com/wordpress/service-providers/wp-json/wp/v2/sp_categories
Categories接口:https://themographics.com/wordpress/service-providers/wp-json/wp/v2/categories返回博客文章类型的默认分类
有没有像https://themographics.com/wordpress/service-providers/wp-json/wp/v2/sp_categories/categories这样的方法
发布于 2020-08-05 22:16:54
如果有人还在寻找解决方案:
全部获取:- https://yoursite.com/wp-json/wp/v2/your-taxonomy
获取单曲:- https://yoursite.com/wp-json/wp/v2/your-taxonomy/id
通过段塞获取单个:- https://yoursite.com/wp-json/wp/v2/your-taxonomy?slug=slugname
在我的例子中,我使用了
https://app.local/wp-json/wp/v2/works-categories
https://app.local/wp-json/wp/v2/works-categories/5
https://app.local/wp-json/wp/v2/works-categories?slug=my-slug-name
来源:similar post
发布于 2017-12-07 15:50:03
你可以这样做:
add_action('init', 'json_handler');
function json_handler(){
$categories = get_terms( 'my_cat', 'orderby=count&hide_empty=0' );
if( ! is_wp_error( $categories ) ) {
// encode the $categories array as json
print_r( json_encode( $categories ) );
}
}https://stackoverflow.com/questions/47669159
复制相似问题