Support

Account

Home Forums Backend Issues (wp-admin) Migrating a repeater into a nested repeater using phpMyAdmin

Solving

Migrating a repeater into a nested repeater using phpMyAdmin

  • Hi

    I have a repeater that is present on around 2,000 posts. “Features”

    A recent request from the client is for more than one block of Features

    So I’ve put in a repeater that enables that “Features Blocks” which has nested “Features”.
    But for the historic posts I have left the original repeater.

    So in the Post Edit there are now two fields Features – a repeater with each row a Feature and Feature Blocks – a repeater with each row a set of Features – in turn a repeater with each row a Feature)

    This is not very elegant and has the power to confuse (never too difficult with the average client)

    What I would like to do (via phpMyAdmin) is to migrate the rows of the original repeater into the repeater contained in the first row of the new repeater.

    Any pointers as to how I can do this?

    Many thanks, Chris

    PS I’ll also post this on the community forum.

  • I’d use the “update” from my sql on the wp-postmeta to change the meta_value of the fields, to the new field key. Make a backup before 🙂

    Update wp_postmeta set meta_value = 'new field key' where meta_value='old field key' and substr(meta_key,1,1) = '_'

    Note that the meta value has to be in the form field_llnmc9c86353a

    The second condition is just to check where are dealing with the right meta

  • This would be extremely difficult to do with phpMyAdmin.

    Existing repeater values in the db

    
    meta_key                                         | value
    --------------------------------------------------------------------------
    {$repeater_name}                                 | {count($repeater_rows)}
    _{$repeater_name}                                | {$repeater_field_key}
    {$repeater_name}_{$row_index}_{$sub_field_name}  | {$sub_field_value}
    _{$repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_key}
    

    what they would need to be changed to

    
    meta_key                                                                             | value
    ---------------------------------------------------------------------------------------------------------------------------
    {$repeater_name}                                                                     | {count($repeater_rows)}
    _{$repeater_name}                                                                    | {$repeater_field_key}
    {$repeater_name}_{$row_index}_{$nested_repeater_name}                                | {count($nested_repeater_rows)}
    _{$repeater_name}_{$row_index}_{$nested_repeater_name}                               | {$nested_repeater_key}
    {$repeater_name}_{$row_index}_{$nested_repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_value}
    _{$repeater_name}_{$row_index}_{$nested_repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_key}
    
  • There isn’t any way that I’d attempt to move values on 2000 posts given my previous comment.

    The best way to do this is to use the load_value hook on the new repeater. In your filter see if the the repeater has a value and remove the values in the old repeater using the same hook on that repeater.

    Caution: Do actually update the database/fields. This way the changes are only made if the client actually save the post.

    In the admin, hide the old repeater field, but leave it in place. The best way to do this is probably adding some custom CSS, but there might be other ways.

    In your template create two possible code blocks, one to show the new repeater and the second to show the old repeater when the new repeater has no values.

    This makes it possible to slowly convert the old to the new as the client updates the posts instead of retroactively updating every post.

    There is a lot of details missing in the above explanation and you’ll need to do some searching to find it. All of it can be found on this forum, likely by me. You will need to understand how to generate values for a nested repeater using the load_value hook. This has been discussed many times here.

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

You must be logged in to reply to this topic.