最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rest api - Wordpress JSON API returns normal site page in html. How do I get it to give me JSON?

programmeradmin3浏览0评论

For example, entering /?json=1 into the browser loads the main site html, the same as omitting the json querystring variable: /

The JSON API is activated. I have tried reactivating and deactivating, checking .htaccess file settings, and deactivating all other plugins. None of those have made much difference so far.

For example, entering http://mywordpresswebsite.example/?json=1 into the browser loads the main site html, the same as omitting the json querystring variable: http://mywordpresswebsite.example/

The JSON API is activated. I have tried reactivating and deactivating, checking .htaccess file settings, and deactivating all other plugins. None of those have made much difference so far.

Share Improve this question asked Apr 21, 2017 at 15:49 n8barn8bar 2191 gold badge3 silver badges11 bronze badges 5
  • 2 what do you men "json api is activated". the api is part of version 4.7 and there is nothing that needs to be activated – Mark Kaplun Commented Apr 21, 2017 at 16:13
  • 1 Touche Mark. But it still doesn't work when the old plugin is deactivated. – n8bar Commented Apr 21, 2017 at 16:19
  • 2 the end point is in /wp-json, have you tried it? – Mark Kaplun Commented Apr 21, 2017 at 16:26
  • 1 I didn't know that but it gave me a 404 error. however, /index.php/wp-json worked. Thank you!! – n8bar Commented Apr 21, 2017 at 16:34
  • 1 if you need the /index.php there is probably something generaly wrong with how permalinks are setup on the site. never saw it myself so not sure what advice to give – Mark Kaplun Commented Apr 21, 2017 at 16:50
Add a comment  | 

3 Answers 3

Reset to default 1

I'm likely doing it wrong, but when I form my requests for a Wordpress installation at http://www.example/ like this:

http://www.example/index.php?rest_route=/my/rest/route/here

I end up getting proper responses back.

I had a heck of a time figuring this out and ended up grokking a URL formatted like that in the HTML returned to me. I was expecting to make requests as http://www.example/wp_json/wp/v2/my/rest/route/here , but I only got HTML responses.

I had the same problem and I solved it setting the permalink in the wordpress and also changing the .htaccess (see https://www.wpbeginner/wp-tutorials/how-to-fix-wordpress-posts-returning-404-error/) to make permalink work correctly.

Ok, so the new endpoint for Wordpress 4.7 is mywordpresswebsite.example/index.php/wp-json. It's part of Wordpress Core as of 4.7 and not a plugin anymore, there's nothing to be activated. Thank you, Mark Kaplun.

发布评论

评论列表(0)

  1. 暂无评论