There doesn’t seem to be any function (or any docs for a function) to get the data on the field groups – for example if I wanted to figure out what group a field was in, and then get the location, description, style, menu_order for that group. Am I missing something here?
An example might be using a meta query to pull all posts with a specific field, but I would need to know the parent field group ID + what post types are enabled as a location for that field group for the query.
And if this is not an option, it would be a great future function as I could see many uses for it!
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