Создание Wordpress REST API на моем собственном плагине - PullRequest
0 голосов
/ 27 февраля 2020

Я делаю Wordpress REST API для моего пользовательского плагина.

Я добавил этот код в конструкцию плагина

add_action('rest_api_init', function () {
  register_rest_route( 'api/pay', 'transactions/(?P<category_id>\d+)',array(
    'methods'  => 'GET',
    'callback' => 'get_latest_posts_by_category'
  ));
});

И сделал так:

function get_latest_posts_by_category($request) {
  $args = array(
    'category' => $request['transaction_id']
  );

  $response = new WP_REST_Response($args);
  $response->set_status(200);
  return $response;
}

Но я не могу назвать мои остальные API.
У меня есть эта ошибка:

{
  "code": "rest_no_route",
  "message": "No route was found matching the URL and request method",
  "data": {
    "status": 404
  }
}
...