Home Forums ACF PRO Add Field Group, PHP vs JSON?


Add Field Group, PHP vs JSON?

  • I am including a field group within a plugin, and was curious as to the best way to add it. Do you have any insight into the performance differences between loading a field group via PHP using acf_add_local_field_group() vs creating a custom load point and saving the configuration in a JSON file? Its seems like the PHP method would create the fields on every request (because it is created as part of the constructor) but could be relatively lightweight, vs the JSON lazy loading which has to read from a file, but presumably only does this as needed.

    Is one method better than the other?


  • Hi @jsilver

    Don’t have any performance benchmarkings for the difference but I would imagine they’re not much different there unless you get it up to insane quantities.

    Personally if it’s fields not within a theme I would always go for the PHP approach. That’s because it’s more straight forward, I find the syntax easier to work with and most importantly it’s dynamic.

    I have a project right now where I create ACF fields in a plugin dynamically based on posts in a CPT using the PHP method 🙂

  • @jonathan That sounds reasonable. Unless it was seriously faster to use JSON, just having a PHP array makes things much easier, plus I can use the same config for ACF4 (with register_field_group()) as well as ACf 5, since ACF4 wouldn’t support the json config. To your last point, it also lets me filter them so I can configure the form on the fly.

    Thanks for confirming I don’t need to refactor anything 🙂

  • No problem @jsilver
    Best of luck with your project!

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

The topic ‘Add Field Group, PHP vs JSON?’ is closed to new replies.