WordPress REST API register_rest_route give a 500 error
Question
I want to create a class to register my custom theme rest routes. After I wrote this piece of code I’ve noticed that the rest api will give a 500 error and axios isn’t able to get the data. I want to make a single page wordpress website by using vue to get the contents of the pages but for now I need to solve this issue. Can anyone help me? Is my code correct?
class Uheme_Rest_Routes {
public static function init()
{
add_action( 'rest_api_init', array( __CLASS__, 'uheme_routes') );
}
public function uheme_routes()
{
register_rest_route(
'uheme/v1',
'/menu',
array(
'method' => 'GET',
'callback' => array($this, '_rest_menu')
)
);
}
public function _rest_menu()
{
return wp_get_nav_menu_items('menu');
}
}
Uheme_Rest_Routes::init();
0
ajax, php, rest-api
3 years
2020-04-06T08:51:02-05:00
2020-04-06T08:51:02-05:00 0 Answers
97 views
0
Leave an answer