Support

Account

Home Forums General Issues Programatically create acf fields after calling rest api upon theme activation

Solving

Programatically create acf fields after calling rest api upon theme activation

  • I need to call rest api and create programatically acf group/fields in in my theme options upon theme activation.

    I tried using the acf_add_local_field_group and acf_add_local_field functions on acf/init action and it worked fine, however this is executed too often and i prefer to call the rest api just once.

    Do you have any ideas or suggestions?

    Thanks!

  • Hi

    I am still looking for solution about this. Anyone has idea about it?

    Thanks,
    Kris

  • There isn’t any way to dynamically create fields through REST. The field need to either be exist in PHP, the DB or as a JSON file.

    I suppose that you could create a field groups and save it as json in the acf-json folder of your theme https://www.advancedcustomfields.com/resources/local-json/

    You might also be able to save the group as a serialized array as an option and then have an init function that reads in all of these options to dynamically add the groups on init… but the json method above would be a better choice.

    As far as I know there aren’t any functions in ACF that can be called to create field groups the way that ACF does it.

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

You must be logged in to reply to this topic.