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

WordPress 外掛 Advanced Custom Routes – Custom Endpoints for WP REST API 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Advanced Custom Routes – Custom Endpoints for WP REST API」是 2019-07-26 上架。
  • 目前有 40 個安裝啟用數。
  • 上一次更新是 2019-07-28,距離現在已有 2106 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.0 以上版本才可以安裝。
  • 有 2 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

lcarlile |

外掛標籤

api | rest | rest-api | custom route | custom endpoint |

內容簡介

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

原文外掛簡介

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

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Advanced Custom Routes – Custom Endpoints for WP REST API」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.8.0 | trunk |

延伸相關外掛(你可能也想知道)

  • Disable REST API 》這是最全面的 WordPress REST API 存取控制外掛!, 輕鬆安裝,安裝後不需要額外設定即可使用。只需上傳並啟用,整個 REST API 將無法被一般訪客存取。, 但如...。
  • Make Connector 》Make 是一個視覺化平台,讓你可以在幾分鐘內設計、建立和自動化任何事情 - 從簡單的任務到複雜的工作流程。使用 Make,你可以在 WordPress 和數千個應用程式...。
  • ACF to REST API 》此 WordPress 外掛在WordPress REST API中提供了Advanced Custom Fields的端點, 詳細資訊請參閱GitHub:https://github.com/airesvsg/acf-to-rest-api/。
  • Disable WP REST API 》這個外掛只有一個功能:禁用沒有登入 WordPress 的訪客使用 WP REST API。不需要任何設定。, 這個外掛只有 22 行短小的程式碼(少於 2KB)。因此它非常輕量、...。
  • WPGet API – Connect to any external REST API 》簡單地連接WordPress至外部API的最簡單方式。, , WPGetAPI 可輕鬆地從無限量的第三方 REST API 發送和接收資料,然後使用「Shortcode」或「Template Tag」格...。
  • WP REST Cache 》如果您在使用 WordPress REST API 時遇到速度問題,這個外掛將允許 WordPress 快取 REST API 的回應,使其更快。, 此外掛提供以下功能:, , 快取所有預設的 W...。
  • WP REST API Controller 》WP REST API Controller 外掛提供使用者易用的圖形化介面,使管理員可以切換 WordPress 核心和自訂文章類型以及分類法的可見性和端點,同時也可以自訂 API 回...。
  • Transbank Webpay REST 》透過 Webpay Plus 和 Webpay Oneclick 在你的 WooCommerce 上使用信用卡、借記卡和預付卡進行在線付款。
  • WordPress REST API (Version 2) 》WordPress 正轉變成一個完整的應用程式框架,因此需要新的 API。這個專案的目的是創建一個易於使用、易於理解且經過良好測試的框架,用於創建這些 API,以及...。
  • WP REST API – OAuth 1.0a Server 》使用這個外掛,您可以將應用程式連接至您的 WordPress 網站,而不必透露您的密碼。, 此外掛使用 OAuth 1.0a 協議,允許委派授權,即允許應用程式使用一組次要...。
  • REST API Meta Support 》此外掛可以自動將 WordPress REST API 的文章(/wp-json/wp/v2/posts)或頁面(/wp-json/wp/v2/pages) POST 中的 meta 欄位所包含的元數據自動存儲於建立的...。
  • Better REST API Featured Images 》注意:您可能不需要此外掛。 REST API 已經支援在 URL 中添加查詢參數 ?_embed,並且回應將包括所有“嵌入式媒體”,包括特色圖片,在那裡獲得的數據正是此外掛...。
  • REST API Toolbox 》此外掛允許調整多個 REST API 設定, , 停用 REST API, 移除 WordPress 核心端點, 需要核心端點驗證, 強制使用 SSL, WP-CLI 命令: wp rest-api-toolbox, , 在 ...。
  • Disable Gutenberg Autosave 》啟用此外掛後,Gutenberg 編輯器的自動儲存功能將被停用。您也可以在編輯器中選擇不同的自動儲存間隔時間(預設為 60 秒)。, 區塊編輯器仍會使用本地自動儲...。
  • WP-CORS 》來自其他網站的 AJAX 請求(其中包含 Origin 標頭)將被允許,並且會允許在外掛程式的「設定」頁面中列出的任何網域。。

文章
Filter
Apply Filters
Mastodon