Coder Social home page Coder Social logo

kodie / migrate-acf-field-data-to-repeater Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 7 KB

A WordPress plugin that migrates field metadata for ACF fields that have been moved inside of a repeater

License: MIT License

PHP 100.00%
acf acf-field acf-fields advance-custom-field data data-migration data-migration-tool wordpress wordpress-plugin

migrate-acf-field-data-to-repeater's Introduction

Migrate ACF Field Data to Repeater WP CLI Command

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.

migrate-acf-field-data-to-repeater's People

Contributors

kodie avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.