Home › Forums › Backend Issues (wp-admin) › ACF fields no longer under Field Groups.
So I’ve run into a snag that I’m hoping can be easily fixed. I’ll try and break this down as easy as possible. The 3 main areas of note are:
acf.php
My acf.php file includes every custom field on my site, it’s up-to-date and works just as you’d expect. No problems here.
My database
Includes all custom fields and data that I’ve added through ACF. No problems here.
Custom Fields (in wp_admin)
This is where it gets strange. Not all of my custom fields are here anymore. They used to be, but somewhere along the line they’ve disappeared. Everything is working on my site; all my data is being displayed, and when I go-to edit a page that uses a custom field, I can do that just fine.
The problem now is that if I want to make changes to the original custom fields (such as add a new input etc) I can no longer do that because they don’t exist under the Custom Fields menu in wp_admin anymore.
I tried converting the acf.php file to json and importing that but it doesn’t update the database to show the fields again.
I’ll give you an example: On my site I’m showing a list of ambassadors. The ambassadors are appearing just fine, but if I want to edit the original custom fields to, say, add a ‘location’ field to their profiles, I can no longer do that.
Is there a way to get everything back up and running and in sync with eachother again?
Apologies if this is a bit incomprehensible, I’m not an experienced developer.
I’m using Advanced Custom Fields PRO 5.3.0.
Any help would be greatly appreciated.
Thanks,
David
I’m on version ACF Pro 5.4.5 plus WordPress 4.6.1 and I’m having the same issue.
I’ve used the PHP method for adding ACF fields to a client project. Unfortunately the actual fields have disappeared from the back-end.
Everything appears to still work because the PHP file is clearly getting activated but no fields are showing to edit within the field group settings.
Fields created in PHP have never appeared in the admin to edit. I’m unsure how you were getting them to do so. If the groups do exist in the database then creating them also in PHP has no effect, if the field group key already exists or the field key already exists then trying to add them with PHP is ignored. Also, when importing a field group, if the field group key already exists then the JSON import will also be ignored. If you want to be able to continue editing the fields then they must be created in the ACF admin only. Like I said, I have no idea how you would have been able to do what you say you were doing.
@hube2 The Field Groups existed before everything was exported into PHP to include them into the project so they could be code versioned across different development workflow environments.
I was expecting to migrate these to local JSON soon, but I can’t now because I can’t export anything with 0 field groups showing up. I used to have dozens of field groups with tons of fields setup in those groups.
The PHP file still exists so the data is still working for the client for any current fields. Clearly something has changed (most likely a recent update) to eliminate all the existing field groups in the project.
At this point I’m left wondering how I’m going to be able to easily make changes when I’m left with only the exported code to make those changes. It’s possible to still make changes via the API this way but that is pretty inefficient compared to the back-end UI built for handling the generation of UI components quickly.
I do this all the time, that is exporting field groups to use in PHP. The field groups in PHP do not work unless I delete the field group from the ACF editor. I’ve been using ACF for a long time and I’ve never seen it possible to have a field group in ACF and created by PHP at the same time, so you were doing a trick with ACF that I wouldn’t be able to do.
If you want to get the field groups into JSON you can to this after the php for creating the group.
$file_name = $group['key'].'.json';
$json = json_encode($group);
then save the json value to the file on the server. http://php.net/manual/en/function.fwrite.php
@hube2 Strange, I was able to have both working side by side. The only requirement was I needed to export the fields any time I needed to make a change since the PHP took precedence. I think it was most likely a version wiping out my local copy I was using.
Thanks for pointing me in the right direction I was able to get it working after use a small function to convert each of the field groups to a .json file.
Here is the code for anyone in need of help:
function acf_field_group_to_json($array) {
$group = json_encode($array);
echo '<p>Writing file to ' . $array['key'] . '.json</p>';
$file = file_put_contents( $array['key'] . '.json', $group );
if ($file) {
echo "<p>". $file . " bytes file created.</p>";
} else {
'<p>Error, file not created.</p>';
}
}
acf_field_group_to_json($array);
Then you would refresh the page and it should generate the field group json file for you at the root of your project/server. A message will output to that page you refreshed in your project. You’d move these group field .json files into an acf-json folder in your theme folder and sync it up on the back-end.
I guess it could depend on when you’re adding the field group. Here is the first part of the function that ultimately gets called when you add a local field group using PHP
/*
* add_field_group
*
* This function will add a $field group to the local placeholder
*
* @type function
* @date 10/03/2014
* @since 5.0.0
*
* @param $field_group (array)
* @return n/a
*/
function add_field_group( $field_group ) {
// validate
$field_group = acf_get_valid_field_group($field_group);
// don't allow overrides
if( $this->is_field_group($field_group['key']) ) return;
As you can see, the second thing that it does is to see if the field group key already exists, if it does it does not include the field group. The field groups in the DB would normally already be created if you added fields in the theme, so the PHP version is ignored. This has been the case since the introduction of the function acf_add_local_field_group() or before.
This also makes it impossible to test whether or not the PHP field groups are actually working or not. The only way to do that on the site the groups are built on is to, at a minimum, put them in the trash.
The topic ‘ACF fields no longer under Field Groups.’ 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.