我也有同样的问题,我在谷歌上搜索,终于在上面答案的帮助下找到了解决方案。这可能会帮助他人。
$this->base = home
register_rest_route(
$namespace, \'/\' . $this->base . \'/\' . \'products\' . \'/\', array(
array(
\'methods\' => WP_REST_Server::READABLE,
\'callback\' => array( $this, \'rest_api_popular_products\'),
),
)
);
register_rest_route(
$namespace, \'/\' . $this->base . \'/\' . \'products\' . \'/(?P<category>[\\d]+)/(?P<sort>[\\w]+)\', array(
\'args\' => array(
\'id\' => array(
\'description\' => __( \'Unique identifier for the resource.\', \'woocommerce\' ),
\'type\' => \'integer\',
),
),
array(
\'methods\' => WP_REST_Server::READABLE,
\'callback\' => array( $this, \'rest_api_popular_products\' ),
\'args\' => array(
\'context\' => $this->get_context_param( array( \'default\' => \'view\' ) ),
),
)
)
);
API请求,如:。。wp json/wc/v2/主页/产品/?类别=89(&;排序=受欢迎程度