Edit/update – using acf_add_local_field_group
and wrapping it in a function to call add_action('acf/init', 'my_wrapper_function');
plus hardcoding the page id at least gets me the fields on the admin side. Form won’t show on the front-end though and hard coding the id’s obviously not a real solution.
TL;DR – When bringing in fields from an exported PHP field group, does register_field_group()
need to come with acf_form_head
before get_header
?
Perhaps this is a little bit more of a WordPress question than a ACF question, but here goes…
I’m working on a plugin that integrates with ACF to display a front-end form and capture/create new posts with the submitted values. I’m basically finished working my locally and am trying to move to my dev server. To do that, I used the “export as PHP” option on my field groups. Fine so far. But, here’s where I’m stuck.
In order to have the fields display on both my “Make a Request” page and the individual posts, I made a rule for ACF
"show the field group if"
Page is equal to Make a Request OR Post Type is equal to request_form (my CPT)
This works fine locally so I exported the PHP imported to my plugin and pushed to dev.
Here’s the problem – In the exported PHP, in the register_field_group
function, this rule is represented in the location
key towards the bottom. There the rule for the page looks like this…
array (
'param' => 'page',
'operator' => '==',
'value' => '4',
'order_no' => 0,
'group_no' => 0,
),
value => '4'
is the id of the page on my local environment, but not the development server or (presumably) any other environment that follow. So…
How can I set this as a variable before the page has loaded (since acf_form_head is called before get_header)?