Home >CMS Tutorial >WordPress >Basic usage of WordPress REST API

Basic usage of WordPress REST API

藏色散人
藏色散人forward
2019-10-02 14:00:129983browse

The following column WordPress Tutorial will introduce you to the basic use of WordPress REST API. I hope it will be helpful to friends in need!

Basic usage of WordPress REST API

The WordPress system opens REST API by default, that is to say, in addition to outputting content in HTML format,

can also output content in JSON format Output article/user/comments and other data.

The reason why JSON data format response is supported is because currently various smart terminal devices, such as mobile phones/tablets/TVs/routers/home appliances/toys, etc.,

have to communicate with the cloud server. Communication, and the data required by the terminal device does not necessarily have to be presented to the user after parsing HTML by the browser.

So JSON, a data format specification that is easy to write/read/parse, is usually used for data communication.

If you have deployed WordPress, you can get data in JSON format through the corresponding link:

Link format example:

Article list/wp- json/wp/v2/posts

Page list/wp-json/wp/v2/pages

User list/wp-json/wp/v2/ users

Replace the example domain name with your own domain name. If the page returns a 404 error, you need to set the redirection rules of the WEB proxy server (Nginx).

For complete resource API link, please visithttps://developer.wordpress.org/rest-api/reference/

here It can be seen that if the website wants to provide data interface services for other devices, it can be used directly without development costs.

If you do not want your website to open the REST API, you can disable this feature by installing the plug-in Disable REST API.

Plug-in address: https://wordpress.org/plugins/disable-json-api/

After installation and activation, in addition to the logged-in administrator, other users No permission to access data.

In order to make JSON data easy to read in the browser, you can install related extensions:

Chrome:

https://chrome.google.com/ webstore/detail/json-viewer/aimiinbnnkboelefkjlenlgimcabobli?utm_source=chrome-ntp-icon

The above is the detailed content of Basic usage of WordPress REST API. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete