Support

Account

Home Forums Backend Issues (wp-admin) Migrated repeater fields visible in front end, but not when editing block

Helping

Migrated repeater fields visible in front end, but not when editing block

  • I submitted a ticket to what now seems to be WP Engine support to no avail, so will post here just in case!

    I have a block called Link List, which well is just a list of links. It was a repeater for manually entered link items but it was updated to include existing site content as well. I seem to have successfully migrated the fields in the old repeater to the fields in the updated repeater, I can see them in block preview and when viewing the block on the front end. However, when editing the block, there are no populated fields to edit.

    Old json – repeater field with three subfields (subhead, url, short_description):

    {
    "key": "field_64837282e5ad9",
    "label": "Old Link List Items",
    "name": "items",
    "aria-label": "",
    "type": "repeater",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "layout": "block",
    "pagination": 0,
    "min": 0,
    "max": 0,
    "button_label": "Add Row",
    "rows_per_page": 20,
    "sub_fields": [
    {
    "key": "field_6483729ae5ada",
    "label": "Old Subhead",
    "name": "subhead",
    "aria-label": "",
    "type": "text",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": "",
    "placeholder": "",
    "prepend": "",
    "append": "",
    "parent_repeater": "field_64837282e5ad9"
    },
    {
    "key": "field_64837357e5adc",
    "label": "Old URL",
    "name": "url",
    "aria-label": "",
    "type": "url",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "placeholder": "",
    "parent_repeater": "field_64837282e5ad9"
    },
    {
    "key": "field_648372afe5adb",
    "label": "Old Short Description",
    "name": "short_description",
    "aria-label": "",
    "type": "textarea",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": 155,
    "rows": "",
    "placeholder": "",
    "new_lines": "",
    "parent_repeater": "field_64837282e5ad9"
    }
    ]
    },

    New json – repeater with three sub fields (entry_method, custom_item, existing_item), the custom_item containing the original three item fields (subhead, url, short_description) from above.

    {
    "key": "field_66b4df4663782",
    "label": "Link List Items",
    "name": "link_list_items",
    "aria-label": "",
    "type": "repeater",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "layout": "row",
    "pagination": 0,
    "min": 0,
    "max": 0,
    "collapsed": "",
    "button_label": "Add Link Item",
    "rows_per_page": 20,
    "sub_fields": [
    {
    "key": "field_66b11540e682f",
    "label": "Entry Method",
    "name": "entry_method",
    "aria-label": "",
    "type": "select",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "choices": {
    "custom": "Custom URL",
    "existing": "Existing Page Content"
    },
    "default_value": "custom",
    "return_format": "value",
    "multiple": 0,
    "allow_null": 0,
    "ui": 0,
    "ajax": 0,
    "placeholder": "",
    "parent_repeater": "field_66b4df4663782"
    },
    {
    "key": "field_6758a9a91df40",
    "label": "Custom Link List Item",
    "name": "custom_item",
    "aria-label": "",
    "type": "group",
    "instructions": "",
    "required": 0,
    "conditional_logic": [
    [
    {
    "field": "field_66b11540e682f",
    "operator": "==",
    "value": "custom"
    }
    ]
    ],
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "layout": "block",
    "sub_fields": [
    {
    "key": "field_6758a8101df3e",
    "label": "Subhead",
    "name": "subhead",
    "aria-label": "",
    "type": "text",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": "",
    "placeholder": "",
    "prepend": "",
    "append": ""
    },
    {
    "key": "field_66b4e13bd37ad",
    "label": "URL",
    "name": "url",
    "aria-label": "",
    "type": "url",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "placeholder": ""
    },
    {
    "key": "field_66b4e13bd37ae",
    "label": "Short Description",
    "name": "short_description",
    "aria-label": "",
    "type": "textarea",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": 155,
    "rows": "",
    "placeholder": "",
    "new_lines": ""
    }
    ],
    "parent_repeater": "field_66b4df4663782"
    },
    {
    "key": "field_66b1161ae6830",
    "label": "Existing Link List Item",
    "name": "existing_item",
    "aria-label": "",
    "type": "relationship",
    "instructions": "",
    "required": 0,
    "conditional_logic": [
    [
    {
    "field": "field_66b11540e682f",
    "operator": "==",
    "value": "existing"
    }
    ]
    ],
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "post_type": "",
    "post_status": "",
    "taxonomy": "",
    "filters": [
    "search",
    "post_type",
    "taxonomy"
    ],
    "return_format": "id",
    "min": "",
    "max": 1,
    "elements": "",
    "bidirectional": 0,
    "bidirectional_target": [],
    "parent_repeater": "field_66b4df4663782"
    }
    ]
    }

    PHP – migrating the old item fields into new Link List Items > Custom Item

    $old_items = get_field('items') ?: [];
    $link_list_items = get_field('link_list_items', $post_id) ?: [];

    if ($old_items) {
    foreach ($old_items as $old_item) {
    $is_duplicate = false;
    foreach ($link_list_items as $existing_item) {
    if (
    $existing_item['entry_method'] === 'custom' &&
    $existing_item['custom_item']['subhead'] === $old_item['subhead'] &&
    $existing_item['custom_item']['url'] === $old_item['url'] &&
    $existing_item['custom_item']['short_description'] === $old_item['short_description']
    ) {
    echo '<p>Duplicate found:</p>

    ';
                    var_dump($old_item);
                    echo '

    ';
    $is_duplicate = true;
    break;
    }
    }

    // If not a duplicate, add to the new structure
    if (!$is_duplicate) {
    echo '<p>Adding new item:</p>

    ';
                var_dump($old_item);
                echo '

    ';
    $link_list_items[] = [
    'entry_method' => 'custom',
    'custom_item' => [
    'subhead' => $old_item['subhead'],
    'url' => $old_item['url'],
    'short_description' => $old_item['short_description'],
    ],
    'existing_item' => null,
    ];
    }
    }

    echo '<p>New link_list_items array to update:</p>

    ';
        var_dump($link_list_items);
        echo '

    ';

    // Update the field with the current + migrated items
    $update_result = update_field('link_list_items', $link_list_items, $post_id);

    // // Check if the update was successful
    if ($update_result) {
    echo '<p>Field updated successfully.</p>';
    } else {
    echo '<p>Failed to update field.</p>';
    }
    }

    Just to reiterate, after running the migration script I can now see the old field data in the new fields on the front end, but if I edit the Link List block it’s as if there is no content.

    Any help troubleshooting this would be appreciated, thanks!

  • Full json for the link list field group, and php/html attached. Not sure why the php format in my post came out like that.

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

You must be logged in to reply to this topic.