高级自定义字段获取某些类型的字段

高级自定义字段获取某些类型的字段

问题描述:

我有一个自定义字段组,我正在使用get_field_object。高级自定义字段获取某些类型的字段

我需要建立一个项目是一个真/假类型字段的列表。这是我迄今为止。

$ type ['true_false']似乎没有返回类型field_object数组中的值。

我看了一下acf文档,只能找到过滤器类型的过滤参考,我不确定它是否适合在这里。

<ul class="has">    
<?php 

    $fieldgroup_id = ('34'); 


     // Get the entries of the field group 
     $custom_field_keys = get_post_custom_keys($fieldgroup_id); 

      // Loop through the field group 
         foreach ($custom_field_keys as $key => $fieldkey) 
         { 

            // Only return fields beginning with 'field_' 
            if (stristr($fieldkey, 'field_')) 
            {          
             $field = get_field_object($fieldkey, $fieldgroup_id); 
             $label = $field['label']; $name = $field['name']; $type = $field['type']; 




// ----------------------------------------------------------- Build List     

            if ($type['true_false'] && get_field($name)) { 


              echo " <li class=\"" . $name . "\">" . $label . "</li>\r\n";  

              }   



           } 
          } 

      ?> 

</ul> 
+0

解决了它,是愚蠢的。 if($ field ['type'] =='true_false') { //做点什么 } – webpod

解决它检查自定义字段类型:

if($field['type'] == 'true_false') { // do something } 

上面的检查,如果它是一个真/假的自定义字段。放在这里,无论你想检查。

感谢Elliot在高级定制领域为这个答案。

Advanced custom fields support forum