Home › Forums › Backend Issues (wp-admin) › Saving Custom Field Group Meta
Hi all.
I’m trying to save some custom field group meta to my acf field group. I want to use this meta to further expand some logic for my wordpress theme.
I am able to get the meta field to show, But no matter what i do i do not seem to be able to save the value to my field group, Hopefully someone can point me in the correct direction.
add_filter(
'acf/field_group/additional_group_settings_tabs',
function ( $tabs ) {
$tabs['additional_settings'] = "Additional Settings";
return $tabs;
}
);
add_filter('acf/field_group/render_group_settings_tab/additional_settings', 'add_additional_settings_fields');
function add_additional_settings_fields($field_group) {
acf_render_field_wrap(array(
'label' => 'Is Component',
'type' => 'true_false',
'name' => 'is_component',
'value' => isset($field_group['is_component']) ? $field_group['is_component'] : 0,
'instructions' => 'Check this box if this Field Group belongs to a component.',
'ui' => 1, //
), 'div', 'acf-field-component-flag');
return $field_group;
}
add_filter('acf/update_field_group', 'save_additional_settings_field_group_settings', 10, 1);
function save_additional_settings_field_group_settings($field_group) {
if (isset($_POST['is_component'])) {
$field_group['is_component'] = $_POST['is_component'];
}
return $field_group;
}
From what I understand, your acf/update_field_group filter should not be necessary. All field group settings are automatically stored. ACF stores field group settings in as a serialized array in “post_content” for the “acf-field-group” post.
I would look there to see if the field is already saved before trying to do it yourself.
Notice that the documentation includes no examples of adding any filters for updating the settings. The only time this should be necessary it when the value should be stored in a different way than ACF is already storing it.
Some other notes
– As far as I can tell acf/update_field_group only happens when saving JSON
– I’m pretty sure the value of your new field will be in $_POST['acf_field_group']['is_component']
and not $_POST['is_component']
`
You must be logged in to reply to this topic.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.