[WordPress] 外掛分享: WUXT Headless WordPress API Extensions

首頁外掛目錄 › WUXT Headless WordPress API Extensions
50+
安裝啟用
尚無評分
2495 天前
最後更新
問題解決
WordPress 4.7.0+ v1.0 上架:2019-05-19

內容簡介

此外掛會為 WordPress Rest API 添加一些擴充功能,旨在使 WordPress 作為 Headless CMS 更易於使用。
它原本是為 WUXT 設計的,WUXT 是一個帶有 NuxtJs 的 Docker 開發環境,用於 Headless WordPress。不過,任何其他需要強大的 Headless WordPress 後端的應用程序都可以使用它。
WordPress API 擴充功能

Frontpage 端點:沒有明顯的方法可以通過 Rest API 獲取 WordPress 首頁。要讀取設置,必須授權,這使事情變得不必要地複雜。新端點返回前頁物件(如果已設定),否則返回最新的十篇文章
菜單端點:目前,我不知道有什麼方法可以從 API 獲取菜單。此端點返回整個菜單作為嵌套數組。默認位置是“main”,但您可以請求其他位置。
Slug 端點:如果您正在 WordPress 上構建前端應用程序,則必須考慮如何結構化您的 URL。 WordPress 有兩個默認的文章類型(文章和頁面),並且在 URL 中沒有區分您正在請求哪種類型,因此 http://wp-site.expl/something 可能會導致頁面或文章,具體取決於帶有 something 標題的對象的類型。如果您想在應用程序中反映這種行為,則必須對每個 URL 做兩個請求,一個用於搜索頁面,一個用於搜索文章。使用 Slug 終點來使其一個請求。
分類篩選並且擴充功能:在使用 Rest API 請求篩選分類時,所有查詢都是 OR 查詢。這意味著您可以獲取在分類 A 或 B 中的文章。我們的調整使您可以將所有分類查詢切換為 AND 關係,這樣您就可以選擇同時在分類 A 和 B 中的文章。
Geo 查詢:如果您的應用程序需要通過地理位置靠近獲取文章,則可以使用 Geo 查詢。
WordPress SEO 元欄位:如果啟用了 Yoast WordPress SEO 插件,它們會自動包含在meta對象中。
高級自訂欄位插件在啟用插件後會自動包含在meta對象中。

端點和參數

Frontpage

GET /wp-json/wuxt/v1/front-page
GET /wp-json/wuxt/v1/front-page?_embed

菜單

GET /wp-json/wuxt/v1/menu
GET /wp-json/wuxt/v1/menu?location=<location>

Slug

GET /wp-json/wuxt/v1/slug/<post-or-page-slug>
GET /wp-json/wuxt/v1/slug/<post-or-page-slug>?_embed

分類篩選並且擴充功能

GET /wp-json/wp/v2/posts/?categories=1,2&and=true

GEO 查詢

GET /wp-json/wp/v2/posts/?coordinates=<lat>,<lng>&distance=<distance><km|m>
GET /wp-json/wp/v2/posts/?coordinates=<lat_meta_field>:<lat>,<lng_meta_field>:<lng>&distance=<distance><km|m>
GET /wp-json/wp/v2/posts/?coordinates=52.585,13.373&distance=10
GET /wp-json/wp/v2/posts/?coordinates=lat_mkey:52.585,lng_mkey:13.373&distance=10
GET /wp-json/wp/v2/posts/?coordinates=52.585,13.373&distance=10m

鏈接

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WUXT Headless WordPress API Extensions」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin adds a couple of extensions to the WordPress Rest API, which are aimed to make the use of WordPress as headless CMS easier.
It is originally coded for WUXT, a dockerized development environment for headless WordPress combined with NuxtJs. However, it can be used by every other application, which needs a powerful headless WordPress back-end.
WordPress API Extensions

Frontpage endpoint: There is no obvious way to get the WordPress front-page via the Rest API. To read the settings, you have to be authorized, which makes things unnecessary complicated. The new endpoint returns the front-page object if it is set, the ten newest posts otherwise.
Menu endpoint: Right now, there is no way I know of, for getting menus from the API. This endpoint returns an entire menu as nested array. Default location is “main”, but you can request other locations.
Slug endpoint: If you are building a front-end app on top of WordPress, you have to think about how to structure your urls. WordPress has two default post-types (posts & pages) and in the urls is not distinguished which type you are requesting, so http://wp-site.expl/something might lead to a page or a post, dependent on the type of the object with the slug something. If you want to mirror that behaviour in your app, you have to do two requests for each url, one searching pages, one searching posts. To make that one request, use the slug end-point.
Taxonomy filter AND extension: When filtering taxonomies with an Rest API request, all queries are OR-queries. That means you can get posts which are either in category A or B. Our adjustment lets you switch all tax_queries to an AND-relation, so that you can select posts which are both in category A and B.
Geo query: If your application has to get posts by geographical proximity, you can use a geo query.
WordPress SEO meta fields: They are included automatically in the meta object if the Yoast WordPress SEO plugin is activated.
Advanced custom fields are included automatically in the meta object if the plugin is activated.

Endpoints and parameters
Frontpage

GET /wp-json/wuxt/v1/front-page
GET /wp-json/wuxt/v1/front-page?_embed

Menu

GET /wp-json/wuxt/v1/menu
GET /wp-json/wuxt/v1/menu?location=

Slug

GET /wp-json/wuxt/v1/slug/ GET /wp-json/wuxt/v1/slug/?_embed

Taxonomy filter AND extension

GET /wp-json/wp/v2/posts/?categories=1,2&and=true

GEO query

GET /wp-json/wp/v2/posts/?coordinates=,&distance=
GET /wp-json/wp/v2/posts/?coordinates=:,:&distance=
GET /wp-json/wp/v2/posts/?coordinates=52.585,13.373&distance=10
GET /wp-json/wp/v2/posts/?coordinates=lat_mkey:52.585,lng_mkey:13.373&distance=10
GET /wp-json/wp/v2/posts/?coordinates=52.585,13.373&distance=10m

Links

More detailed end-point description
WUXT
WUXT release blog post
NuxtJs

Credits

Michael Cox Menu Class for returning a menu as array

文章
Filter
Mastodon