Support

Account

Home Forums Gutenberg Repeater Field in Gutenberg Block Disappears

Solving

Repeater Field in Gutenberg Block Disappears

  • I have created a field group in my theme which container a few fields, one of which is a repeater. When this is added to the page, I can add and save as normal. If I then move the block from the bottom of the page to anywhere else, it then breaks the repeater. The other fields still contain their values, however the repeater has no rows and I see no content in post_content in the database.

    My field group:

    
    acf_add_local_field_group([
    	'key' => 'features_grid_block_group',
    	'title' => 'Features Grid',
    	'fields' => [
    		[
    			'key'           => 'features_grid_image',
    			'label'         => 'Background Image',
    			'name'          => 'background_image',
    			'type'          => 'image',
    			'return_format' => 'array',
    			'preview_size'  => 'thumbnail',
    			'mime_types'    => 'jpg, jpeg'
    		],
    		[
    			'key'   => 'features_grid_title',
    			'label' => 'Title',
    			'name'  => 'grid_title',
    			'type'  => 'text'
    		],
    		[
    			'key'   => 'features_grid_text',
    			'label' => 'Summary',
    			'name'  => 'grid_text',
    			'type'  => 'textarea'
    		],
    		[
    			'key'          => 'features_grid_features',
    			'label'        => 'Features',
    			'name'         => 'features_grid_repeater',
    			'type'         => 'repeater',
    			'layout'       => 'table',
    			'button_label' => '',
    			'sub_fields'   => [
    				[
    					'key'           => 'features_grid_feature_image',
    					'label'         => 'Feature Image',
    					'name'          => 'feature_image',
    					'type'          => 'image',
    					'return_format' => 'array',
    					'preview_size'  => 'thumbnail',
    					'mime_types'    => 'jpg, jpeg, png',
    				],
    				[
    					'key'   => 'features_grid_feature_text',
    					'label' => 'Feature Text',
    					'name'  => 'feature_text',
    					'type'  => 'text'
    				]
    			]
    		]
    	],
    	'location' => [
    		[
    			[
    				'param' => 'block',
    				'operator' => '==',
    				'value' => 'acf/cwc-features-grid',
    			]
    		]
    	]
    ]);

    Adding this to the page and saving gives me the following post_content markup (appears after all other wp: elements

    <!-- wp:acf/cwc-features-grid {"id":"block_5cdab9017e19c","data":{"features_grid_image":"","features_grid_title":"Features Grid End","features_grid_text":"Summary text here","features_grid_features":{"row-0":{"features_grid_feature_image":"17","features_grid_feature_text":"first feature"},"row-1":{"features_grid_feature_image":"17","features_grid_feature_text":"second feature"},"row-2":{"features_grid_feature_image":"17","features_grid_feature_text":"third feature"}}},"name":"acf/cwc-features-grid","align":"","mode":"auto"} /-->

    If I move the block up the page, the markup changes to:

    <!-- wp:acf/cwc-features-grid {
        "id": "block_5cdab9017e19c",
        "data": {
            "background_image": "",
            "_background_image": "background_image",
            "grid_title": "Features Grid End a",
            "_grid_title": "features_grid_title",
            "grid_text": "Summary text here a",
            "_grid_text": "features_grid_text",
            "features_grid_repeater": "",
            "_features_grid_repeater": "features_grid_features"
        },
        "name": "acf\/cwc-features-grid",
        "align": "",
        "mode": "auto"
    } /-->

    Is there a way for me to debug the issue, or have I got some of the acf_add_local_field_group syntax wrong?

  • If you’re worried the acf_add_local_field_group() syntax is wrong, you could instead create the field group inside the WordPress dashboard (Custom Fields > Add New).
    and then export it as PHP (Custom Fields > Tools > Select Field Group > Generate PHP).

    Don’t forget to remove the field group again once you’ve put it in PHP.

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

The topic ‘Repeater Field in Gutenberg Block Disappears’ is closed to new replies.