Home › Forums › Backend Issues (wp-admin) › [q] Is it possible to add fields automatically after adding in other group? › Reply To: [q] Is it possible to add fields automatically after adding in other group?
Hi @razider
I believe you can use the acf/update_field_group
and acf_update_field()
function to do that. Here’s a simple example you can try:
add_action('acf/update_field_group', 'my_acf_add_custom_field');
function my_acf_add_custom_field($field_group){
// set ID of field groups you want to update
$field_group_ids = array(4002);
// loop through the IDs
foreach( $field_group_ids as $field_group_id ){
// set the new field data
$field = array(
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
'parent' => $field_group_id
);
// add the field
$field_id = acf_update_field($field);
}
}
I hope this helps 🙂
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.