I’m confused… what’s the point of exporting the PHP of a field group if using that php on the site causes problems?
As you mentioned, those steps will not recreate the issue, now that we know the issue is caused by exporting the fields to PHP and then implementing that PHP in a config.php for a template.
I’m fine with having to re-export the php if I make changes to the field group in ACF. But I don’t understand why the exported PHP running on the site would cause the fields in ACF to vanish.
In my case I have a template for a landing page that has 2 standard components. a config.php that is used to define the fields for the page, and an index.php that reads those fields.
All I’m doing is exporting the field group and adding it to the config.php for my template so when I create a page that uses that template the proper fields show up for building the page.
As far as my customization to the theme, there really isn’t any. The only real PHP contents of the config.php are what I pasted above. (the register_field_group array)
The only real change to the array is the addition of template_id to the location array:
'location' => array ( array ( array ( 'param' => 'post_type', 'operator' => '==', 'value' => 'landing-page', ), array ( 'param' => 'template_id', 'operator' => '==', 'value' => $key, ) ), ),
That is used so the fields are only show up for that specific template.
I could potentially avoid implementing the exported fields PHP in config.php if there were a way in ACF to add template_id == XXX in locations, but that does not appear to be an option.
I was able to get things to ALMOST work by removing the register_field_group content form the config.php and then having the ACF field group location target a specific landing page post. The problem there is a single post can implement any number of templates. So I need to target a post that uses a specific template_id, otherwise these fields show up for all landing page posts regardless of template.
So post_type == landing page is supported, but targeting a specific template is not. (see screenshot)
So very very close!
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!