0

I am working through the documentation on wp-api.org/ and trying to get my head around this awesome plugin, but I have a question that I can't find the answer to anywhere, so thought I'd ask...it's probably quite simple, but hey ho..

Whilst exploring the json data my install is spitting out (by going to localhost/wordpress/wp-json/), the routes seem to be different to every example in the documentation on wp-api.org.

Instead of the routes to the posts being

/wp-json/posts

my route is

/wp-json/wp/posts

and so on for pages etc. I was wondering what causes this change, and how you would go about removing the

/wp/ 

/wp-json/posts from the route

1
  • That's goofy. It sounds like it's something in your wordpress settings though, not with the wp rest api.
    – Jacksonkr
    May 7, 2015 at 4:48

2 Answers 2

1

In the latest version of the API (2.0 ) the wp part is the namespace of core, default routes. This means that the core routes have URLs like "wp-json/wp/posts", while a custom route would be something like "/wp-json/woo-comm/sizes".

The documentation just hasn't caught up yet.

Which version are you using?

1

I know this is an older question, but for posterity's sake and for those finding this question later, wp is the namespace and you shouldn't remove it. This is how you know that the request is core functionality.

It's an important way to separate custom endpoints from WP core endpoints and keeps the REST routes consistent.

If, for example, you have a plugin called Widgeteer which has a CPT called widgets, and want to add REST endpoint to get widget by ID you might do the following:

/wp-json/widgeteer/v1/widgets/123

Just looking at this, you can see that the endpoint is part of the widgeteer plugin, it's version 1 of the API, you're getting widgets with an id of 123 ( which obviously should result in only 1 widget returned ).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.