0

I have a custom field group, and I am using get_field_object.

I need to build a list with items that are a true/false type field. This is what i have so far.

$type['true_false'] does not seem to be returning the value in the field_object array for type.

I have had a look at the acf documentation and can only find reference to filtering by type in the filter section, which i'm not suree if it is appropriate here.

<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> 
4

1 回答 1

1

Solved it to Check custom field type:

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

The above checks if it is a True/False custom field. Put in here whatever you want to check for.

Thanks to Elliot at Advanced Custom fields for this answer.

Advanced custom fields support forum

于 2013-11-04T10:21:09.613 回答