kodie/migrate-acf-field-data-to-repeater

A WordPress plugin that adds the `wp migrate-acf-field-data-to-repeater` command to WP CLI. That command renames the keys of metadata so that they are prepended with the repeater slug so that the fields can be moved into a repeater along with their data.

v0.0.1 2022-11-11 18:34 UTC

This package is auto-updated.

Last update: 2024-05-06 22:17:44 UTC


README

Warning: This plugin and command should be considered experiemental. Use at your own risk. Be sure to test thoroughly before using in a production environment.

A WordPress plugin that adds the wp migrate-acf-field-data-to-repeater command to WP CLI. That command renames the keys of metadata so that they are prepended with the repeater slug so that the fields can be moved into a repeater along with their data.

For example: I have a field created with ACF named item_description and I have been using it on pages so that field has content in it on multiple pages. Later on I decided that I want a repeater field named items and I want item_description to be in that repeater. Well, I can easily drag the field into the repeater and there we go! Except, not really. The previously entered data for item_description will not appear in the new repeater field. That's where this command comes into play.

Use this command after you have already created your new repeater field and moved the fields you with to migrate into the repeater from the Custom Fields page.

wp migrate-acf-field-data-to-repeater <repeater_slug> <repeater_field_id> <field_slug...> [--dry-run] [--post_type=POST_TYPE] [--include=POST_ID,POST_ID,POST_ID...]

  • repeater_slug - The "name" field for the repeater. Example: items
  • repeater_field_id - This is the field ID for the repeater. To find this, you'll need to go to a page on the WordPress backend that has the field, inspect the element, and it should be in the for attribute for the repeater label prepended with "field_". Example: 636d5921b3451
  • field_slug - The "name" field for the field(s) you wish to move into the repeater. Seperate multiple slugs with a space. Example: item_title item_description
  • --dry-run - Set this option to display the results without actually making any changes.
  • --post_type and --include - You can actually use any options to pass to the get_posts function. Seperate multiple values with a comma. Example: --post_type=page --include=47,82 --author_name=bob

Command example:

$ wp migrate-acf-field-data-to-repeater items 636d5921b3451 item_title item_description --post_type=page --include=27

Easily install, activate, and use the plugin via:

$ composer require kodie/migrate-acf-field-data-to-repeater
$ wp plugin activate migrate-acf-field-data-to-repeater
$ wp migrate-acf-field-data-to-repeater ...
$ wp plugin deactivate migrate-acf-field-data-to-repeater
$ composer remove kodie/migrate-acf-field-data-to-repeater

Thanks

This plugin was originally inspired by this gist by @gthayer.

License

MIT. See the license.md file for more info.