Wordpress REST API 开发

简介

Wordpress v4.4以后,已经内置了WP REST API。

接口文档:https://developer.wordpress.org/rest-api/


The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects. It is the foundation of the WordPress Block Editor, and can likewise enable your theme, plugin or custom application to present new, powerful interfaces for managing and publishing your site content.


RESTful API 路由地址

所有接口地址都以 /wp-json/ 开始,比如获取文章列表的地址是 http://oursite.com/wp-json/wp/v2/posts

Posts	                /wp/v2/posts
Post Revisions	        /wp/v2/posts//revisions
Categories	            /wp/v2/categories
Tags	                /wp/v2/tags
Pages	                /wp/v2/pages
Page Revisions	        /wp/v2/pages//revisions
Comments	            /wp/v2/comments
Taxonomies	            /wp/v2/taxonomies
Media	                /wp/v2/media
Users	                /wp/v2/users
Post Types	            /wp/v2/types
Post Statuses	        /wp/v2/statuses
Settings	            /wp/v2/settings
Themes	                /wp/v2/themes
Search	                /wp/v2/search
Block Types	            /wp/v2/block-types
Blocks	                /wp/v2/blocks
Block Revisions	        /wp/v2/blocks//autosaves/
Block Renderer	        /wp/v2/block-renderer
Block Directory Items	/wp/v2/block-directory/search
Plugins	                /wp/v2/plugins



输出友好数据

在 /wp-inclue/functions.php 中找到该函数,添加 JSON_UNESCAPED_UNICODE。

function wp_json_encode( $data, $options = 0, $depth = 512 ) {
	// $json = json_encode( $data, $options, $depth );
	$json = json_encode( $data, JSON_UNESCAPED_UNICODE, $depth );

	.....

	// return json_encode( $data, $options, $depth );
	return json_encode( $data, JSON_UNESCAPED_UNICODE, $depth );
}



未完待续

真诚赞赏,手留余香
赞赏
随机推荐
防止表单重复提交的几种策略
uniapp 开发笔记 (二)
CSS实现图片模糊
ThinkCMF URL美化
vim 教程
Photoshop 抠图技巧笔记
什么是加载占位图(Skeleton Screen Loading)
macOS 自动登录 ssh
无法启动mysql服务 错误1067:进程意外中止
微信接入验证与回复消息