He is my current custom API:
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/get', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_form'
));
});
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/post', array(
'methods' => 'POST',
'callback' => 'post_form'
));
});
Here is something I would like to write, but I'm not sure if it is possible. What I'm sure is that this syntax i
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
'methods' => 'GET',
'callback' => 'GET_form',
), array(
'methods' => 'POST',
'callback' => 'post_form',
), );
});
He is my current custom API:
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/get', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'get_form'
));
});
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/form', '/post', array(
'methods' => 'POST',
'callback' => 'post_form'
));
});
Here is something I would like to write, but I'm not sure if it is possible. What I'm sure is that this syntax i
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
'methods' => 'GET',
'callback' => 'GET_form',
), array(
'methods' => 'POST',
'callback' => 'post_form',
), );
});
Share
Improve this question
asked Apr 12, 2019 at 14:34
TTTTTT
3291 gold badge4 silver badges17 bronze badges
4
|
1 Answer
Reset to default 3Check if your code looks like this because in the question you pass each method as separate function arguments (I have overlooked it earlier)
add_action( 'rest_api_init', function () {
register_rest_route('my-project/v1/', '/form',
array(
array('methods' => 'GET',
'callback' => 'GET_form',
),
array('methods' => 'POST',
'callback' => 'post_form'
)
)
);
});
As you can read in documentation:
Parameters #
$args - (array) (Optional)
Either an array of options for the endpoint, or an array of arrays for multiple methods.
Default value: array()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745596084a4635123.html
$args
- Either an array of options for the endpoint, or an array of arrays for multiple methods. – nmr Commented Apr 12, 2019 at 14:45