高级自定义字段未显示在模板中

时间:2021-03-09 23:15:35

标签: wordpress advanced-custom-fields

我绞尽脑汁想为什么这不起作用。对我来说似乎是对的,但我一定错过了一些东西。

<?php
    if( have_rows('cta_box') ):
        while( have_rows('cta_box') ) : the_row();
            echo get_sub_field('cta_header');
            echo get_sub_field('cta_content');
        endwhile;
    endif;
?>

enter image description here

enter image description here

我在做蠢事吗? 谢谢

3 个答案:

答案 0 :(得分:0)

这是一个组字段,而不是中继器。 This'd 帮助。

所以在你的情况下,你会像这样使用它。

$cta = get_field('cta_box');

echo $cta['cta_header'];
echo $cta ['cta_content];

答案 1 :(得分:0)

您的代码是正确的,我认为问题在于您希望在特定模板中的位置或页面中的任何位置显示,您只需要分配模板或页面或发布其将显示的任何内容。

答案 2 :(得分:0)

这是让它工作的代码。有人可以解释一下吗?此 ACF 上方的代码是否影响返回的内容?

<?php while ( have_posts() ) : the_post(); 
    $cta = get_field('state_call_to_action');
    echo $cta['call_to_action_heading'];
    echo $cta['call_to_action_body'];
endwhile; ?>