Roots Discourse

ACF - json not generated in resources/acf-json/

Hi everyone.

I’ve got ACF running on a clean Sage 9 installation and want to use its JSON functionality for version control. However, nothing shows up in the acf-json folder that I created in /resources.

I found some older threads that indicate that the issue has been resolved, but I seem to be out of luck.
Does anyone have any pointers? I’ve tried adding the acf/settings/save_json filter to see if that had any effect. I also tried the alternative locations mentioned in the Github thread.

That’s not core Sage functionality. Sage doesn’t do anything with ACF and json out of the box. You might be thinking of a library I wrote to to do this?

Ahh, could this thread have been better suited to the Bedrock category, then?
Anyway, I’ve installed your library and started up yarn again but it still doesn’t generate any json when I create field groups. I made sure to remove the not-working filter I had put in place so there wouldn’t be any clashes, too.

Did you install the library in your Sage directory, or your Bedrock directory? It should be in Sage. If the resources/acf-jaon directory doesn’t exist you’ll need to create it. ACF will generate its json on save, so go to one of your field groups and click update.

I installed it in my Sage directory (/site/web/app/themes/<my-theme>, right?) and created the acf-json directory in resources, but updating and creating field groups still has no effect.

It sounds like something else might be going on if both your filter and this library didn’t work. Maybe check your permissions? Is this a Trellis site?

Yep, it’s a Trellis site. Basically the full Roots stack with no additions aside from the ACF as Composer Dependency guide.

I can’t find any weird permissions - any ideas about possible candidates?

So I took a closer look, and figured out that get_stylesheet_directory() (used by the resource I linked to in my initial post) returns an absolute path on the vagrant machine, something like /srv/www/project-name/current/web/app/… and that for some reason doesn’t seem to be working with the ACF filter.
I couldn’t figure out why that didn’t work, so instead, I went with this:

add_filter('acf/settings/save_json', function ($path) {
    return dirname(__FILE__) . '/acf-json';
});

Which points to a acf-json directory that I created relative to the location of the script; in my case, I just jammed it into my functionality plugin.
I also added similar code for the load_json filter.
Hope this helps anyone that runs into this problem, and thanks MWDelaney for quick attempts to help when I posted this!

2 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.