[WordPress] 外掛分享: Field Helper Functions For ACF Pro

首頁外掛目錄 › Field Helper Functions For ACF Pro
WordPress 外掛 Field Helper Functions For ACF Pro 的封面圖片
全新外掛
安裝啟用
尚無評分
244 天前
最後更新
問題解決
WordPress 5.0+ PHP 7.4+ v1.1.0 上架:2025-08-09

內容簡介

### 外掛總結:

- 外掛提供了一組簡單且功能強大的輔助函數,用於減少樣板代碼並簡化檢索和顯示 ACF 欄位值的過程。
- 包括獲取單一值(支援嵌套群組)的輔助函數,以及輕鬆循環遍歷重複器字段。
- 外掛考慮了安全性和最佳實踐,確保所有輸出都可以正確地進行轉義。

### 問題與答案:

1. 什麼是外掛中提到的 get_acf() 函數?
- 答: get_acf() 是一個多功能函數,用於獲取任何字段值,支持嵌套群組字段的點記號,並在重複器中自動處理 get_sub_field() 上下文。

2. 如何從選項頁面獲取字段值?
- 答:在 ACF 選項頁面中獲取字段值的方法是通過將 option 作為 $post_id 傳遞。

3. 重複器函數 repeater() 有什麼特點?
- 答:repeater() 函數簡化了重複器字段的循環。它包括了可選的回調函數,用於主循環前後以及允許將參數數組傳遞給行回調函數。

4. 如何將參數傳遞給重複器模板的回調函數?
- 答:可以通過定義參數數組並在 repeater() 調用中傳遞來使重複器模板更具可重用性。

外掛標籤

開發者團隊

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

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Field Helper Functions For ACF Pro」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin provides a set of simple, powerful helper functions to reduce boilerplate code and streamline the process of retrieving and displaying ACF field values in your templates. It includes helpers for getting single values (with support for nested groups), and for easily looping over repeater fields. The plugin is built with security and best practices in mind, ensuring that all output can be properly escaped.
Features:

get_acf(): A versatile function to get any field value. It supports dot notation for nested group fields and automatically handles get_sub_field() context within repeaters.
repeater(): A clean way to loop through repeater fields with callbacks. Includes optional callbacks for before and after the main loop, and allows passing an arguments array to the row callback. (Requires ACF Pro)
get_repeater_field(): Fetch a specific sub-field value from a specific row, or an array of all values for a sub-field across all rows. (Requires ACF Pro)
Lightweight and secure.
Logs to the PHP error log for easy debugging.

Usage Examples:
get_acf()
This is your main function for retrieving any ACF field value.

Basic Usage: Get the value of a text field named page_headline.

Providing a Default Value: If the page_subtitle field might be empty, provide a fallback.

Escaping HTML: When outputting a value inside an HTML attribute, always escape it.
";

Other escape options: html, url, js, text.

Getting a Value from an Options Page: To get a field value from an ACF Options Page, pass option as the $post_id.
' . get_acf('member_name', '', 'html') . '

';
endwhile;
endif;

repeater() (ACF Pro Only)
This function simplifies looping over repeater fields.

Basic Repeater Loop: To display a list of testimonials from a repeater named testimonials with a sub-field testimonial_text:
' . get_acf('testimonial_text', '', 'html') . '

';
});

Using Before and After Callbacks: To wrap your repeater output in

文章
Filter
Apply Filters
Mastodon