I get 500 error on wp-json.

if I try to echo get_rest_url() I get example.com/wp-json, which then gives me error 500. I added RewriteCond %{REQUEST_URI} !^/wp-json to my .htaccess, which gave me 404 error instead.

I use postname as settings for permalinks. I’ve tried http://example.com/?rest_route=/wp-json/v2/posts as well, and it gives me error 500.

EDIT:
Okay, I turned on wp_debug. Now I get the error: Fatal error: Call to undefined function register_rest_route() in /customers/0/2/1/. So this is my new error. Any clue for this?

2 Answers
2

Are you trying to use that function without first initiating it in an action? It should be done like so:

add_action( 'rest_api_init', 'add_custom_users_api');

function add_custom_users_api()
{
    register_rest_route( 'route', array(
                                'methods' => 'GET',
                                'callback' => 'function',
                       ));
}

Leave a Reply

Your email address will not be published. Required fields are marked *