小智 5
对于类别名称,应添加两个过滤器,如下所示:
add_filter( "rest_post_query", function( $args, $request){
if ( isset( $request['category_name']) && !empty($request['category_name'] ) ) {
$args['category_name'] = $request['category_name'];
}
return $args;
}, 10, 2);
add_filter( "rest_post_collection_params", function($query_params, $post_type){
$query_params[ 'category_name' ] = array(
'description' => __( 'Category name.' ),
'type' => 'string',
'readonly' => true,
);
return $query_params;
}, 10, 2);
Run Code Online (Sandbox Code Playgroud)
这个问题与论坛上的另一个问题重复
http://example.com/wp-json/wp/v2/posts?categories=20,30
Run Code Online (Sandbox Code Playgroud)
以上将返回来自 category 20 OR category 30
我已经使用自定义帖子类型进行了测试,它也可以完美运行
回应和学分归“Manish Jung Thapa”所有
归档时间: |
|
查看次数: |
10722 次 |
最近记录: |