Answer the question
In order to leave comments, you need to log in
How to add new field for ACF group using PHP?
Hello. I've been looking for information on this topic all day and can't find anything. So I need to programmatically add new fields to the ACF group. As soon as possible, I used the acf_add_local_field function. No result. By debugging, I see that the function reaches $store->set( $key, $field )->alias( $key, $name );
And everything seems to be ok, but the fields are not added. Please tell me if anyone had this situation and how did you solve it. You only need to create a field, without creating a group.
Answer the question
In order to leave comments, you need to log in
Are you sure you read the documentation? I just tested some examples from here and everything works
if ( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_1',
'title' => 'My Group',
'fields' => array (),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
));
acf_add_local_field(array(
'key' => 'field_1',
'label' => 'Sub Title',
'name' => 'sub_title',
'type' => 'text',
'parent' => 'group_1'
));
endif;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question