Wordpress Rest API中的动态查询字符串参数

时间:2019-03-12 11:48:32

标签: wordpress wordpress-rest-api

我在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网址的最后一部分将是动态部分,并且将是值数组之一

0 个答案:

没有答案