我在Wordpress rest api文档中找不到有关如何将动态字符串作为url的一部分传递的任何信息,我知道如何进行ID识别。
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<type>)', [
'args' => [
'type' => [
'description' => __('Type of notification to generate', $this->pluginName),
'type' => 'string',
'enum' => ['product_question']
]
],
[
'methods' => \WP_REST_Server::CREATABLE,
'callback' => [$this, 'create_item'],
'permission_callback' => [$this, 'create_item_permissions_check'],
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE)
],
'schema' => [$this, 'get_public_item_schema']
]);
上面是用于尝试注册路线的代码。路由应如下所示:/notifications/product_question
网址的最后一部分将是动态部分,并且将是值数组之一