i have been using this code to get all fields from a specific group:
<?php
$GroupOrPostSlug = 'acf_specialgroup';
//or insert the ID of your fields Group.
$groupID='';
global $wpdb;
if (empty($groupID))
{$groupID = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '$GroupOrPostSlug' ");}
if (empty($groupID))
{$groupID = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$GroupOrPostSlug' ");}
$custom_field_keys = get_post_custom_keys($groupID);
foreach ( $custom_field_keys as $key => $fieldkey )
{
if (stristr($fieldkey,'field_'))
{
//echo $key . " => " . $fieldkey . "<br />";
//echo $field['label'] . ': ' . $field['value'];
//echo $fieldkey . "<br />";
$field = get_field_object($fieldkey, $groupID);
echo $field['label'];
}
}
?>
but it displays only fields’ names. doesnt there exist a simple hook/function, something like this: get_all_fields_from_group($id)
Thank you so much for your post, I spent half day to figure out how to get field names by their group.
If you have field names, you can easily get their values: get_field($field[‘name’]);
EXAMPLE HOW TO GET IMAGES FOR SLIDER
Thanks again!
I’m surprised no one mentioned
acf_get_fields('someGroupId')
yet.Here’s a function I created to get a group’s fields:
In case anyone stumbled upon this page like I did, and tried to figure this out, these methods won’t work anymore with Version 5 and above of Advanced Custom Fields as it’s usings posts instead of postmeta.
In that environment, this is the way I was able to get fields from a group and use them as values for a select field:
Since ACF uses custom posts of type ‘acf’ as groups, we can use get_page_by_title to retrieve the group’s ID, and then do the rest. Here’s a small utility function:
Usage:
If someone is still searching.
You can just do it like this: