ACF - 在灵活内容字段中获取复选框值

时间:2016-08-03 03:44:28

标签: php wordpress checkbox advanced-custom-fields

一直在四处走动,无法让它发挥作用 - 可能是非常简单但我没有留下头发 - 有人可以帮我吗?

<?php
if( have_rows('page_content') ):
while ( have_rows('page_content') ) : the_row();

    if( get_row_layout() == 'specs' ):

        // check if the nested repeater field has rows of data
        if( get_sub_field('objectives') ):
        echo '<ul>';
        $field = get_field_object('objectives');
        $value = $field['value'];
        $choices = $field['choices'];

            // loop through the rows of data
            foreach( $value as $v):
                echo '<li>'.$choices.'</li>';

            endforeach;
            echo '</ul>';
        endif;
    endif;
endwhile;
endif;
?>

提前致谢。

2 个答案:

答案 0 :(得分:0)

你可以试试这样的ACF字段,

$this->getParentFieldDescription()->getOptions();

https://www.advancedcustomfields.com/resources/get_field_object/

答案 1 :(得分:0)

立即行动......感谢ACF的支持团队。在$。$选择之后,我错过了[$ v]。下面的工作代码:

<?php
if( have_rows('page_content') ):
while ( have_rows('page_content') ) : the_row();

if( get_row_layout() == 'specs' ):

    // check if the nested repeater field has rows of data
    if( get_sub_field('objectives') ):
    echo '<ul>';
    $field = get_field_object('objectives');
    $value = $field['value'];
    $choices = $field['choices'];

        // loop through the rows of data
        foreach( $value as $v):
            echo '<li>'.$choices.'</li>';

        endforeach;
        echo '</ul>';
    endif;
endif;
endwhile;
endif;
?>