Php ACF选择前面的输出选项
我试图得到一个选择字段,它有两个子字段,一个是带有预定义值的textfield,另一个是post对象(product),我想在其中提取url和拇指 花了相当多的时间尝试不同的选择,特别是如何检索产品,但没有运气 为了简化这个过程,我开始研究类似的东西,尽管它不能帮助我正确地检索我想要的产品信息,但这也不起作用Php ACF选择前面的输出选项,php,wordpress,advanced-custom-fields,Php,Wordpress,Advanced Custom Fields,我试图得到一个选择字段,它有两个子字段,一个是带有预定义值的textfield,另一个是post对象(product),我想在其中提取url和拇指 花了相当多的时间尝试不同的选择,特别是如何检索产品,但没有运气 为了简化这个过程,我开始研究类似的东西,尽管它不能帮助我正确地检索我想要的产品信息,但这也不起作用 $choice = get_sub_field('block_one_ select_type'); if ($choice == 'checkbox') { // do somethin
$choice = get_sub_field('block_one_ select_type');
if ($choice == 'checkbox') {
// do something
} elseif ($choice == 'product') {
$product = get_field('pdp_product_one');
// do something
}
我也尝试过这个,没有输出:
if(have_rows('pdp_banner', 'options')){
while(have_rows('pdp_banner', 'options')){
the_row();
$test = get_sub_field('block_one_select_type');
}
}
echo $test;
这是ACF设置:
array(
'key' => 'field_5f7efd01f2427',
'label' => 'PDP banner',
'name' => 'pdp_banner',
'type' => 'group',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'group',
'button_label' => 'banner block',
'sub_fields' => array(
array(
'key' => 'field_5f7efd35f2428',
'label' => 'Block one select type',
'name' => 'block_one_select_type',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'checkbox' => 'Checkbox',
'product' => 'Product',
),
'default_value' => array(
),
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
'ajax' => 0,
'return_format' => 'value',
'placeholder' => '',
),
array(
'key' => 'field_5f7efde2f2429',
'label' => 'Checkbox',
'name' => 'checkboxfield',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5f7efd35f2428',
'operator' => '==',
'value' => 'checkbox',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
'default_value' => '<i class="fas fa-check font-size-60 white width-1em"></i>',
),
array(
'key' => 'field_5f7f050f2d6e7',
'label' => 'Product',
'name' => 'pdp_product_one',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5f7efd35f2428',
'operator' => '==',
'value' => 'product',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'product',
1 => 'product_variation',
),
'taxonomy' => array(
),
'taxonomy' => '',
'allow_null' => 1,
'multiple' => 0,
'return_format' => 'object',
'ui' => 1,
),
),
),
数组(
“键”=>“字段_5f7efd01f2427”,
“标签”=>“PDP横幅”,
“名称”=>“pdp_旗帜”,
'类型'=>'组',
'说明'=>'',
“必需”=>0,
“条件逻辑”=>0,
“包装器”=>数组(
'宽度'=>'',
“类”=>“”,
“id'=>”,
),
“崩溃”=>“,
“min”=>0,
“最大值”=>0,
“布局”=>“组”,
'按钮标签'=>'横幅块',
“子字段”=>数组(
排列(
“键”=>“字段_5f7efd35f2428”,
“标签”=>“块一选择类型”,
“名称”=>“块一选择类型”,
'类型'=>'选择',
'说明'=>'',
“必需”=>0,
“条件逻辑”=>0,
“包装器”=>数组(
'宽度'=>'',
“类”=>“”,
“id'=>”,
),
“选项”=>数组(
'复选框'=>'复选框',
“产品”=>“产品”,
),
“默认值”=>数组(
),
'allow_null'=>0,
“多个”=>0,
'ui'=>0,
“ajax”=>0,
“return_format'=>“value”,
'占位符'=>'',
),
排列(
“键”=>“字段_5f7efde2f2429”,
“标签”=>“复选框”,
'name'=>'checkboxfield',
'类型'=>'文本',
'说明'=>'',
“必需”=>0,
“条件逻辑”=>数组(
排列(
排列(
“字段”=>“字段_5f7efd35f2428”,
“运算符”=>“==”,
'值'=>'复选框',
),
),
),
“包装器”=>数组(
'宽度'=>'',
“类”=>“”,
“id'=>”,
),
“return_format'=>“array”,
'默认值'=>'',
),
排列(
“键”=>“字段_5f7f050f2d6e7”,
“标签”=>“产品”,
“名称”=>“pdp_产品_one”,
'type'=>'post_object',
'说明'=>'',
“必需”=>0,
“条件逻辑”=>数组(
排列(
排列(
“字段”=>“字段_5f7efd35f2428”,
“运算符”=>“==”,
“值”=>“产品”,
),
),
),
“包装器”=>数组(
'宽度'=>'',
“类”=>“”,
“id'=>”,
),
“post_type”=>数组(
0=>“产品”,
1=>“产品变化”,
),
“分类法”=>数组(
),
“分类法”=>“”,
'allow_null'=>1,
“多个”=>0,
“return_format'=>“object”,
'ui'=>1,
),
),
),
如果有任何帮助,我们将不胜感激。好吧-您的
echo$test
在while循环
之外,因此在您将其放入该循环之前,它可能不会回显任何内容好吧-您的echo$test
在while循环
之外,因此在您将其放入该循环之前,它可能不会回显任何内容