WordPress REST API接口大全:提升开发效率的终极指南
在当今数字化时代,WordPress REST API 已成为开发者不可或缺的工具。无论是开发小程序、APP还是网站,这些内置API接口都能显著降低开发成本。
In today's digital age, the WordPress REST API has become an indispensable tool for developers. Whether building mini-programs, apps or websites, these built-in APIs can significantly reduce development costs.
一、文章接口 | Article APIs
1. 获取最新文章 | Get latest posts
默认获取10篇最新文章:
http://www.website.com/wp-json/wp/v2/posts
Default gets 10 latest posts:
http://www.website.com/wp-json/wp/v2/posts
2. 分页控制 | Pagination control
获取第二页数据:
http://www.website.com/wp-json/wp/v2/posts?page=2
Get second page data:
http://www.website.com/wp-json/wp/v2/posts?page=2
二、分类标签接口 | Category & Tag APIs
1. 获取所有分类 | Get all categories
http://www.website.com/wp-json/wp/v2/categories
2. 获取指定标签 | Get specific tag
http://www.website.com/wp-json/wp/v2/tags/3
三、高级搜索功能 | Advanced Search
1. 关键词搜索 | Keyword search
搜索包含"SEO"的文章:
http://www.website.com/wp-json/wp/v2/posts?filter[s]=SEO
Search posts containing "SEO":
http://www.website.com/wp-json/wp/v2/posts?filter[s]=SEO
2. 相关文章推荐 | Related posts
随机获取6篇同标签文章:
http://www.website.com/wp-json/wp/v2/posts?filter[orderby]=rand&filter[tag]=library&filter[posts_per_page]=6
Randomly get 6 posts with same tag:
http://www.website.com/wp-json/wp/v2/posts?filter[orderby]=rand&filter[tag]=library&filter[posts_per_page]=6
四、其他常用接口 | Other Common APIs
1. 媒体文件 | Media files
获取指定媒体:
http://www.website.com/wp-json/wp/v2/media/17
Get specific media:
http://www.website.com/wp-json/wp/v2/media/17
2. 用户信息 | User information
获取所有用户:
http://www.website.com/wp-json/wp/v2/users
Get all users:
http://www.website.com/wp-json/wp/v2/users
提示:将"www.website.com"替换为您实际的网站域名
Tip: Replace "www.website.com" with your actual domain