I created several field groups and fields and exported them to PHP. I included this php file in the functions.php.
But since there are no fields created from the ACF dashboard, which ACF filter can be used to get the field groups?
I tried the same function acf_get_field_groups
but that did not work. It only works when the fields are created in the database in the ACF admin page but not when they are registered by PHP.
When are you trying to get the field groups? What hook? Before or after ACF initializes?
I just did a test and acf_get_field_gorups()
is getting all of my field groups, no matter where they are created, in the admin, from JSON files or added using PHP.
@hube2 OK, yes you’re right. I just tested it as well. I am getting the field groups just fine. I am getting them in a plugin after ACF initialized.
However, I am not getting all the fields in each field group. I am only getting the fields of the last field group in the PHP file under each field group.
How are you doing this? Seeing code might help.
This reply has been marked as private.
Field groups loaded with JSON or PHP do not have an ID value. If they do, it is probably 0 as a default.
$fields = acf_get_fields($this->group['ID']);
Using the ID to get the field group assumes that all field groups are in the database. Fields for each group should be gotten using $group[‘key’].
That solved the issue! Thank you!