Because I’ll be moving my theme from server to server, I want to set up all my field groups programatically. I’ve had no problem doing this in the past with custom post type field groups but I have been unable to get it to work for the standard options page. I initially set up the field group using the ui and then exported it as json and pasted that into my php. I also converted it back to a PHP array just in case that made a difference. Here’s my array:
$siteOptions = array (
array (
'key' => 'group_5ca4e11ac450e',
'title' => 'Site options',
'fields' =>
array (
array (
'key' => 'field_5ca4e1333328c',
'label' => 'Announcement',
'name' => 'announcement',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' =>
array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' =>
array (
array (
array (
'param' => 'options_page',
'operator' => '==',
'value' => 'acf-options-site',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
),
);
register_options_page('Site');
acf_add_local_field_group($options);
The crucial part is the location element. This is the parameter that appears in the admin url and it is correct. This was a later attempt after I’d already failed to add the options to the native ACF options page using the value 'acf-options'
.
On the options page I just get an alert stating that no field groups have been created for this options page.
I’ve not found any explicit instructions relating to the use of this function to set up an options field group, but likewise I’ve not found anything to say it shouldn’t work.
Version in use is 5.8.0-beta4.1