簡體   English   中英

類別頁面上的 ACF 組

[英]ACF group on category page

我使用高級自定義字段 ( https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/ ) 為我的博客類別創建了字段組。

當我創建基本文本字段時,很容易在 category.php 上使用:

$terms = get_the_terms( get_the_ID(), 'category');

if( !empty($terms) ) {
    $term = array_pop($terms);
    $custom_field = get_field('some_text_field', $term );
}

echo $custom_field;

但是我創建了一個組(稱為 call_to_action)而不是基本的文本字段,其中包含 4 個字段(圖像、標題、副標題、鏈接)。 現在,如果我嘗試創建不同的變量,例如:

$custom_field1 = get_field('image', $term );
$custom_field2 = get_field('title', $title );
$custom_field3 = get_field('subtitle', $title );
...

並回應他們,什么也沒有發生。

我猜這是因為它們位於“call_to_action”組中......我真的不知道如何讓它們出現......我只是從 PHP 開始,任何想法都會非常感謝

試試這個方法

$custom_field3 = get_field('subtitle');

或者

global $post;  
$custom_field3 = get_field('subtitle',$post->ID);

或者

$custom_field3 = get_field('subtitle',get_the_id());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM