rest_no_route custom route
Question
I get a rest_no_route
error if I try to use a custom endpoint I’ve created. Is there any solution? I’m creating my theme routes inside a plugin class, but I don’t think this is a problem.
I’m using axios to get the data on front-end.
class theme_Rest_Routes extends WP_REST_Controller{
public static function init()
{
add_action( 'rest_api_init', array( __CLASS__, 'register_routes') );
}
public function register_routes()
{
register_rest_route( 'theme/v1', '/menu/', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'theme_rest_menu'))
);
}
public function theme_rest_menu( $request )
{
return wp_get_nav_menu_items('menu');
}
}
theme_Rest_Routes::init();
0
ajax, rest-api
3 years
2020-04-06T08:51:00-05:00
2020-04-06T08:51:00-05:00 0 Answers
105 views
0
Leave an answer