Hello I am having an error whenever I try to create a custom route in WordPress. I am creating my own API and I want to create a custom url route like this:
add_action('rest_api_init', 'universityRegisterSearch');
function universityRegisterSearch() {
register_rest_route('university/v1', 'search', array(
'methods' => WP_REST_SERVER::READABLE,
'callback' => 'universitySearchResults'
));
}
function universitySearchResults() {
return 'Congratulations, you created a route.';
}
and I keep getting this error every time:
404 Error with Custom URL Route
This is the url i am testing with: http://fictional-university.local/wp-json/university/v1/search
Is there another solution to this? Thanks!

It looks to me you are doing everything correctly. Using your function I can open the custom route, no problem.
URL:
/wp-json/university/v1/search- maybe try a conflict check next or maybe your custom function is not properly running.Kind regards,