Home Forums General Issues Add field group inside flexible layout via code


Add field group inside flexible layout via code

  • I’m trying to place a field group inside several of my flexible field layouts.

    A lot of my layouts have repeating fields. Like Title, Title Tag, Title Color. Right now I have to add these to each layout. And if I need to make changes, I have to update each layout. I prefer to have a separate field group for the Title, Title Tag and Title Color. Then place those inside the subfields array alongside the layout-specific fields.

    Before, I did this via a clone field. The field group itself was set to ‘disabled’. But now I’m trying to use ACF via code instead of the web interface. But there’s no clone field available through code.

    I’ve experimented a bit with the functions acf_get_fields(), acf_get_local_field_group(), acf_get_local_field_groups(), but fail to leverage them to accomplish this.

  • Why do you say there is no clone field available when using PHP?

    If this is because it’s not listed in the documentation, the documentation does not cover everything. You should be able to create a clone field.

    Create a clone field with settings you want to use. Then go to tools and generate PHP for the field group containing the clone field. Use that generated code as an example:

    	'key' => 'field_629780ffac6a2',
    	'label' => 'Clone',
    	'name' => 'clone',
    	'type' => 'clone',
    	'instructions' => '',
    	'required' => 0,
    	'conditional_logic' => 0,
    	'wrapper' => array(
    		'width' => '',
    		'class' => '',
    		'id' => '',
    	'clone' => array(
    		0 => 'group_5cdd8ef037a51',
    	'display' => 'seamless',
    	'layout' => 'block',
    	'prefix_label' => 0,
    	'prefix_name' => 0,
  • Thanks so much. That was indeed the reason. I couldn’t find any documentation, anywhere, regarding clone fields via code.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.