Support

Account

Home Forums Feedback Json vs PHP Export

Solved

Json vs PHP Export

  • Basically, which are the differences between exporting fields in php vs exporting in json format? Why I should use a format instead of another?

    Actually, I’m exporting fields in php and including these files directly into my theme folder, or, sometimes, in a custom plugin.

    Maybe could be useful give some suggestions about using these formats.

    Thank you very much in advance.

  • It really depends on what you want to do.

    If you export to JSON you need to read in the file to register the field group. Translation of labels cannot be done using JSON, at least I don’t think they can. JSON files a good if you will use the field group without altering it. JSON also make it easier to modify the group in the future since you and import the group, work on it, and then export it again. This is the biggest plus, especially if you’re going to distribute a plugin or theme and there’s a chance it can change in the future. Reading JSON files will cause a theme to fail the theme check. It has a rule about reading files.

    PHP is good if you want to build something dynamic. Field groups that may or may not be used based on other settings. Fields that may or may not be used based on settings or the current site. PHP does not require opening and reading files so it will pass the theme check. If you want to modify the group using ACF in the future you’ll need to rebuild the group manually unless you also have a JSON copy of it for import.

  • Ah so if a field is registered via PHP register_fields function it doesn’t show up in the Fields admin section? Or it will if it has already been entered there but otherwise it will not?

    I am not sure from the documentation if I want to create fields using the interface, but save them using PHP so it’s not database dependent what the workflow there would be.

  • A field group in PHP or as a JSON file will not show up in the ACF admin unless you import a JSON file.

    If a JSON file exists in the themes acf-json folder, that field group will be loaded without showing the field group in the ACF admin it the field group does not already exist there. You can set multiple load points. So you could have your plugin have it’s own folder for loading JSON files from. However you can only have one save point, so when editing field groups in ACF the JSON files can be automatically saved, but only to one location.

  • Hi @hube2, thanks for the clarifying.

    Based on this considerations I suppose that:

    – json format is better for making BACKUP of fields as well as export fields for IMPORT them in other wordpress applications.

    – php format is better for deploing fields for USING them in a wordpress application.

    I’m using ACF in a wordpress network environment where I build custom fields groups in the main website. Then, I export them in php and put them in a plugin for using in all subsites. Subsites are customers websites.

    This way I can:
    – update easily all custom fields in one time
    – deploy updated custom fields in all subsites in one time
    – show/hide fields based on specific website settings
    – Translate fields in more languages
    – avoid fields editing and compromising

    In this scenario I can export everything in json just to have a backup of all fields and field groups.

  • I have a couple of multisite WP installs. One of them is for a single company that has many sites for each branch office. All of the sites use the same theme. What I did was I created 2 themes. One of them is on a sub site where I maintain the ACF field groups. When I updated one of the groups it is saved into the theme’s acf-json folder. The other theme is used on the sites and in that theme I load the field groups from the management theme. This allows me to easily maintain and alter the field groups as needed while preventing the client from being able to access and change them. I did this because I knew that this company would likely be a long term client and I also knew that I would need to make changes as time went by. In this case the ACF JSON in Pro has saved me a lot of work when changes are needed.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Json vs PHP Export’ is closed to new replies.