Hi,
I’ve got a quick question regarding the fantastic ACF Pro: is there a way to auto import a json export file upon theme/ACF installation?
I’m building a theme with some custom fields and it would be great if i could export the custom fields from my “test” site, include that in a theme download package and have it imported once the theme is actived (and ACF is auto-activated using the TGM activation plugin).
Beats having to export the code, add that code to a php file and include that PHP file. Simply overwriting a json file every time i make a change to the custom fields would be super!
Let me know!
I was just about to ask the same thing. According to v5 features:
The .json files can also be used on other websites even if the field group does not exist in the database. This allows you to create fields on your local website, commit the updated or new .json files and push them to your live website.
I’ve just set up my project on staging and after activating ACF and the theme with JSON configs, I’d expect fields to auto-apply but they didn’t.
Is there a bug or am I misunderstanding this feature?
That looks like it should work, going to test it out and report back! Thanks a lot! 🙂
Hi Derk,
I am also trying to do what you describe in the first post. Did you get it to work?
I am also experiencing this issue as well. I have everything working locally, but when I move the project files, the custom fields are lost.
I’ve followed the guide in the link and check permissions etc. Is there something about the database version of the fields that could be causing an issue?
Hey,
Just noticed this thread and don’t know whether what I have achieved is the same functionality you are searching for.
For the move to production, I renamed the “acf-json” folder to “fields” and had the following code run on init.
$dir = new DirectoryIterator( get_template_directory() . '/fields/' );
foreach( $dir as $file )
{
// var_dump( $file );
if ( !$file->isDot() && 'json' == $file->getExtension() )
{
$array = json_decode( file_get_contents( $file->getPathname() ), true );
register_field_group( $array );
}
}
It doesn’t import the fields, but still registers them. The benefit of doing it this way is the client can’t go in a modify fields from the backend.
so is there a “nice” solution? Even with the Docs i don’t get it.
Hi guys.
The local JSON feature only works to register field groups at run time, not import them into the DB and be able to edit them,
This is a feature which will be added soon!
Thanks
E
is there any progress?
what tables/fields in the DB are beeing used to store field groups etc?
maybe its not too complicated to write some small sql update file.
Not really auto-importing but there’s been a single-click sync button now for a while. So if you have your json files with your template, syncing is a breeze.
If our multisite blogs are all using the same theme, is there any reason why we shouldn’t simply let them load from the local-json at runtime?
Why import them if it’s already loading them?
I’m hoping to manage them on my local install, and then push them to the live server.
I just had the same wish: “Simply overwriting a json file every time i make a change to the custom fields would be super!”.
In my case I found out that the exported json-file had these [] brackets at the beginning and ending of the file and the sync-file did not.
So I just took my exported json-file and deleted the brackets in the first [ and last ] line and then it was loading.
I hope this helps somebody :).
Would be nice if the files would be identical though!
The topic ‘Auto import json export 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.