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

WordPress 外掛 Field Helper Functions For ACF Pro 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Field Helper Functions For ACF Pro」是 2025-08-09 上架。
  • 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
  • 上一次更新是 2025-08-10,距離現在已有 199 天。
  • 外掛最低要求 WordPress 5.0 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

awhittaker |

外掛標籤

acf | utilities | development | advanced custom fields |

內容簡介

### 外掛總結:

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

### 問題與答案:

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

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

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

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

原文外掛簡介

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

    and

  • tags.
    ' . get_acf('service_name') . '
  • ';
    },
    [], // No args needed for this example
    function() { // Before callback
    echo '

      ';
      },
      function() { // After callback
      echo '

    ';
    }
    );

    Passing Arguments to the Callback: To make your repeater template more reusable, pass in arguments.
    'faq-item',
    'heading_level' => 'h3'
    ];

    repeater(
    'faqs',
    function($index, $args) {
    printf('

    ', esc_attr($args['item_class']));

    printf(
    '<%s>%s',
    esc_attr($args['heading_level']),
    esc_html(get_acf('question')),
    esc_attr($args['heading_level'])
    );

    echo '

    ' . get_acf('answer', '', 'html') . '

    ';
    },
    $args
    );

    get_repeater_field() (ACF Pro Only)
    Use this to get data from a repeater field without looping through it manually.

    Get All Values from a Sub-Field:
    Total attendees: ' . count($all_attendees) . '

    ';

    Get a Value from a Specific Row:

    各版本下載點

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

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


    1.1.0 | trunk |

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

    • Autoclear Autoptimize Cache 》Autoptimize 是 WordPress 上一款熱門的性能優化外掛。除了其他功能外,Autoptimize 可以建立和生成已優化資源檔案的快取版本,從而減少頁面加載時間。, 但如...。
    • PW WooCommerce Exclude Free Shipping 》假設您的客戶在購物車中有以下產品:, , 紙飛機, 撲克牌盒, 一架三角鋼琴, , 您提供「滿 $50 免運費」優惠,但指定某些限制。, 理所當然,運送三角鋼琴的成本...。
    • Export Plus 》WordPress內建的匯出工具限制您的數據匯出方式,並提供非常有限的選項。這個外掛透過巧妙地使用核取方塊(而非單選框),添加了一個包含更多彈性選項的新匯出...。
    • QuickLogin 》QuickLogin 是一款針對自建 WordPress 網站的外掛,提供類似 Squarespace 的 Esc 鍵偵測功能,用戶可以在觀看網站時按下「Esc」鍵來顯示登錄面板,如果用戶還...。
    • Dynamic Cart Messages for WooCommerce 》Dynamic Cart Messages 可以讓您在 WooCommerce 網站上,透過在購物車頁面顯示量身打造的訊息,來激勵您的顧客增加您喜好的產品或產品類別的數量或金額,進而...。
    • WP Utility Script Runner 》有時候你會遇到需要手動執行程式的情況。實際上的邏輯可能只是從查詢生成一個 CSV 檔,或者更改使用者的設定,甚至只是執行一行 SQL。然而在 WordPress 上這...。
    • Change Titles Case 》此外掛完全免費,不提供專業版本。詳細資訊請參閱專門網站和WordPress插件協助。, 請瀏覽我的網站以查看截圖和更多資訊。, 我創建此外掛的初衷是為了協助轉換...。
    • Amuga Ajax Log 》現在是時候找出真正造成你的 admin-ajax.php 檔案負載過重的原因了。, 與普遍信念相反,對 admin-ajax.php 的負荷不僅僅來自「Heartbeat API」。許多外掛利用...。
    • Disable All WordPress Updates and Theme Editors 》Disable All WordPress Updates, File Editors and Gutenberg 是一個方便的工具,允許你在 WordPress 上禁用所有類型的自動更新、插件和佈景主題,佈景主題-...。
    • Page/Post Converter for WPBakery to Elementor 》總結:這個外掛可以讓使用者選擇頁面複製並將 WPBakery 短碼轉換成 Elementor 元素,詳細內容如下:, , 1. 這個外掛可以做什麼?, - 可以讓使用者選擇要複製...。
    • MyBrain Utilities 》總結:這個外掛是由My Brain設計用於不同網站的各種工具的集合,我們將其發布到WordPress Plugin存儲庫中,認為這也對他人有用。, , 1. HTAccess_Keeper, ...。
    • YM Site Kit 》總結:YM Site Kit 提供一系列小型、實用的工具,旨在使與 WordPress 網站合作更加便利高效。此外採用了開發和管理數十個 WordPress 網站的經驗,包括最常用...。
    • All-in-One Utilities 》總結:All-in-One Utilities 是一個多功能的外掛,讓管理員可以透過啟用必要功能來簡化他們的 WordPress 網站。以這些主要功能有效地減少網站開銷並管理使用...。
    • WPBackupEssentials 》WPBackupEssentials 讓您可以輕鬆地在幾個簡單的點擊中備份整個 WordPress 網站。, 您可以輕鬆地備份 WordPress 網站檔案和資料庫資訊,因為 WPBackupEssenti...。
    • Utilitify – Supercharge Your WordPress Site With Powerpack WordPress Utilities 》這是一個簡單而整潔的外掛,可幫助您以非常優雅的方式自定義 WordPress 設定。, 功能, , 👉 404 重新導向 , 解決所有隨機出現在您網站上的 404 鏈接,使用 ...。

文章
Filter
Mastodon