Home Forums ACF PRO Get Field Group Metadata? Reply To: Get Field Group Metadata?

  • The only way to get a field group based on a field would be to query the DB to get the “post” for the field and then look at the “post_parent”. This value will either be another ACF field “post” (for sub fields) or an ACF field group “post”. There is not function in ACF that will allow this to be done.

    You can get field groups based on specific parameters. This function is not documented. It is not really meant for general use. I also cannot give any specific on how to use it because I just don’t have that information. This function is acf_get_field_groups() and can be found the file /includes/acf-field-group-function.php on about line 319, in the plugin folder. Using this function alone will return a list of all field groups. Supplying arguments will filter the list of groups.

    This function calls acf_filter_field_groups() which then calls acf_get_field_group_visibility(). This last function filters the groups by the location rules of each group.

    For example, you could get a list of groups that would be shown on a specific post by using $groups = acf_get_field_groups(array('post_id' => $post_id));

    Please be aware that because these functions are not documented there is not guarantee that they will exist in the future or that the way they work will not change. That said, I know this function has existed since ACF 5.0.0