Support

Account

Home Forums General Issues How to check for the current field group

Helping

How to check for the current field group

  • Hey, I’m using the following code to print all fields values related to the current post:

    <?php
    // Custom fields section
    $fields = get_field_objects();
    
    if ( !empty($fields) ){
    
    	/* Sorting the array based on fields menu order */
    	foreach ( $fields as $key => $field ){
    		$menu_order[$key] = $field["order_no"];
    	}
    
    	array_multisort($menu_order, SORT_ASC, $fields);
    
    	echo "<dl class='clearfix'>";
    	foreach ( $fields as $field ){
    
    		if (empty($field['value']))	continue;
    
    		echo "<dt>".$field['label']."</dt><dd>".$field['value']."</dd>";
    		echo '<br class="clear">';
    
    	}
    	echo "</dl>";
    }

    ?>

    However, I put another field group that shouldn’t be part of that section, how do I exclude fields related to that group from the above loop? something like
    if( in_group($field['id'], $group_id ) continue;

    Is there anyway to do that?

  • If you’re looking to get the fields of just one field group then instead of using get_field_objects() I would use an internal ACF functions that is not in the standard documentation

    
    $fields = acf_get_fields($group_key);
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to check for the current field group’ is closed to new replies.