如何在数组内传递值?

时间:2017-10-26 13:30:10

标签: php wordpress

我有一个有这个选择的数组

    $choices = array(
        '-- Make a Selection --' => '',
        'Choice 1' => 'Choice 1',
        'Choice 2' => 'Choice 2',
        'Choice 3' => 'Choice 3',
        'Choice 4' => 'Choice 4',
        'Choice 5' => 'Choice 5'
    );
    return $choices;

我需要使用自定义字段转发器(高级自定义字段)填充的选项

if(have_rows('lista_de_variables')) : while(have_rows('lista_de_variables')) : the_row(); 

    $choice = get_sub_field('dimension');

endwhile; endif;

// this function returns an array of 
// label => value pairs to be used in
// a the select field
$choices = array(
    '-- Make a Selection --' => '',
    $choice => $choice,
);
return $choices;

2 个答案:

答案 0 :(得分:0)

你应该直接使用数组的字段

$choice = get_field('lista_de_variables');
print_r($choice);

有关acf的转发器字段的更多信息,您可以 访问https://support.advancedcustomfields.com/forums/topic/print-repeater-array-values/

答案 1 :(得分:-1)

而不是使用

DynamicPropertyDescriptor

你可以简单地使用

$choices = array(
    '-- Make a Selection --' => '',
    $choice => $choice,
);
相关问题