我正在嘗試將自定義網址結構添加到基於WordPress的網站。將WordPress地圖自定義網址轉換爲函數
例如:
example.com/machines //list all machines in a table
example.com/machines?some=params //list filtered machines in a table
example.com/machines/1 //show single machine
的數據將來自我已經開發了一個外部API,通過捲曲。
我無法將數據導入到自定義帖子類型中,因爲它在許多表上進行了規範化,業務邏輯非常複雜,並且無論如何其他設備都使用api。
我看過的文檔進行add_rewrite_rule,但第二個參數已經難倒我:
$redirect
(string) (required) The URL you would like to actually fetch
嗯,我沒有一個URL來獲取,我想運行一個功能,即會採取行動一個簡單的路由器 - 獲取url部分,調用外部API並返回帶有正確數據的模板。
調用API將很簡單,但我如何實際將路由到該函數,然後我如何加載模板(利用現有的WordPress header.php和footer.php)讓我難住。