[WordPress] 外掛分享: Advanced Custom Routes – Custom Endpoints for WP REST API

首頁外掛目錄 › Advanced Custom Routes – Custom Endpoints for WP REST API
WordPress 外掛 Advanced Custom Routes – Custom Endpoints for WP REST API 的封面圖片
40+
安裝啟用
★★★★★
5/5 分(2 則評價)
2426 天前
最後更新
問題解決
WordPress 4.0+ v0.8.0 上架:2019-07-26

內容簡介

REST API 是 WordPress 的一個重要補充,讓人們能夠透過預設路由來輕鬆取得數據。然而,這些預設路由最大的問題是要麼取得的數據太多,要麼太少,並且並不容易只取得所需的數據。這個外掛就能夠創建自定義路由,讓你可以設置只拉取你需要或想要的數據。更好的是,你甚至不需要碰到一行代碼就能夠運作,所有設置都可以在 WordPress 控制台中進行配置。

功能 ⚡️

無限自定義路由
自定義路由命名
自定義篩選以僅收到所需數據
選擇要輸出的字段
查詢參數
無煩惱的體驗

使用方法

要開始使用高級自定義路由,請轉到 WordPress 控制台,然後選擇自定義路由部分。
接下來,點擊「新增」來創建您的第一個自定義路由。
為自定義路由命名,開始配置所需的自定義路由。
查詢構建器選項:選擇如何篩選您想在此自定義路由中接收的文章。
回應輸出:選擇您想要在此自定義路由中接收的字段。
當你配置好了所有設置後,發佈自訂路由,您現在就能在這條路由上接收您選擇的數據。

查詢構建器選項

文章、頁面和自訂文章類型
文章 ID
分類
標籤
作者
文章的父節點
狀態
順序和排序方式
日期
金額和偏移量

回應輸出

ID
標題
內容
摘要
連結
Slug
發布日期
狀態
特色圖像
類別
標籤
作者
文章類型
範本
文章的父節點
選單順序
自訂欄位

路由參數

您還可以使用查詢參數過濾自定義路由,將其添加到自訂路由的末尾,像這樣:

https://example.com/wp-json/custom-routes/v1/posts?id=1

在上面的示例中,它只會在文章的 ID 等於 1 時提取此自訂路由的數據。這可以用於多個不同的查詢參數:

金額
偏移量
頁面
文章類型
id
id_exclude
分類
category_exclude
標籤
tag_exclude
作者
author_exclude
文章的父節點
post_parent_exclude
狀態
date_before
date_after
order
orderby
slug
search
page

單篇文章路由

您還可以使用 ID 或 Slug,在自定義路由上接收單篇文章的數據,例如:

ID:
https://example.com/wp-json/custom-routes/v1/posts/1

(這會在此自定義路由中獲取 ID 為 1 的文章)

Slug:
https://example.com/wp-json/custom-routes/v1/posts/hello-world

(這會在此自定義路由中獲取 slug 為 hello-world 的文章)

如何安裝 Advanced Custom Routes。
使用 WordPress Plugin Directory

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.8.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Advanced Custom Routes – Custom Endpoints for WP REST API」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

The REST API was a great additional to WordPress that made it easy to grab data through the default routes. The biggest issue with these default routes is it will either grab too much data or too little data and it didn’t make it easy to only grab the data you need. This plugin makes it possible to create custom routes where you can set to pull only the data you need/want. Even better you won’t even have to touch a line of code to make it work, everything will be configurable within the WordPress dashboard.
Features ⚡️

Unlimited custom routes
Custom route naming
Custom filtering to only receive data you need
Select which fields to output
Query parameters
A hassle-free experience

How to use

To start using Advanced Custom Routes, go to the WordPress dashboard and select the Custom Routes section.
Next click ‘Add New’ to create your first custom route.
Give your custom route a name and start configuring your custom route to what you need.
Query Builder Options: Select how to filter the posts you would like to receive at this custom route.
Response Output: Select which fields you would like to receive at this custom route.
Once you have configured everything to your liking, publish the custom route and you will now be able to receive your selected data at this route.

Query Builder Options

Posts, Pages, and Custom Post Types
Post ID
Categories
Tags
Author
Post Parent
Status
Order & Orderby
Date
Amount & Offset

Response Output

ID
Title
Content
Excerpt
Link
Slug
Date Posted
Status
Featured Image
Categories
Tags
Author
Post Type
Template
Post Parent
Menu Order
Custom Fields

Route Parameters
You can also filter your custom routes using query parameters that you add to the end of your custom route like so:
https://example.com/wp-json/custom-routes/v1/posts?id=1

In the example above it would only pull data for that custom route where the post’s ID was equal to 1. This can be used for multiple different query parameters:

amount
offset
page
post_type
id
id_exclude
category
category_exclude
tag
tag_exclude
author
author_exclude
post_parent
post_parent_exclude
status
date_before
date_after
order
orderby
slug
search
page

Single Post Route
You can also receive data for a single post at a custom route using either an ID or a Slug, like so:
ID:
https://example.com/wp-json/custom-routes/v1/posts/1

(This would grab the post with an ID of 1 at this custom route)
Slug:
https://example.com/wp-json/custom-routes/v1/posts/hello-world

(This would grab the post with the slug of hello-world at this custom route)
How to install Advanced Custom Routes.
Using WordPress Plugin Directory
Navigate to the ‘Add New’ in the plugins dashboard
Search for ‘Advanced Custom Routes’
Click ‘Install Now’
Activate the plugin on the Plugin dashboard
Uploading it to WordPress
Navigate to the ‘Add New’ in the plugins dashboard
Navigate to the ‘Upload’ area
Select advanced-custom-routes.zip from your computer
Click ‘Install Now’
Activate the plugin in the Plugin dashboard
Via FTP
Download advanced-custom-routes.zip
Extract the advanced-custom-routes directory to your computer
Upload the advanced-custom-routes directory to the /wp-content/plugins/ directory
Activate the plugin in the Plugin dashboard

延伸相關外掛

文章
Filter
Apply Filters
Mastodon