Home › Forums › Backend Issues (wp-admin) › Get ACF fields from PHP file
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.
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’].
The topic ‘Get ACF fields from PHP file’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.