The ACF (Advanced Custom Fields Pro) Elliot is one of the best methods for quickly adding Custom Fields to your WordPress Posts / Custom Posts. A nice feature of the plugin is the intuitive method of grouping together fields in ‘Field Groups’. Oddly the ACF documentation doesn’t fully cover how to output all fields in a particular group. Here’s our approach:-
Output all Fields in ACF Field Group
// enter your Field ID in 123 $fields = acf_get_fields(123); if( $fields ) { foreach( $fields as $field ) { $value = get_field( $field['name'] ); if(!empty($value)) { echo '<dl>'; echo '<dt>' . $field['label'] . '</dt>'; echo '<dd>' .$value . '</dd>'; echo '</dl>'; } } }
Tip
The ACF field group is visible in the URL when you edit the Field Group >i.e. /wp-admin/post.php?post=123&action=edit
Why not make this into a Shortcode?
For handy including into your WordPress front-end you can easily make the above into a WordPress shortcode by wrapping it with the following PHP in your Child Theme functions.php file:-
// ACF Group Shortcode function shortcode_acfgroup( $atts ){ // start // add the above php here // end } add_shortcode( 'acfgroup', 'shortcode_acfgroup' );
To add in your ACF Group Fields simply then add the shortcode [acfgroup]