• Resolved Sean

    (@avidflow)


    Hi,

    If say, I had a 100 entries in a custom post type called “Movies”. Can I move these from a CPT to a new Custom table with the plugin or is the plugin only for creating a custom table?

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Abhishek

    (@abhisheksatre)

    Hi @avidflow,
    Currently our plugin does not support migration of existing data. It stores data in a custom table whenever you update an article.

    You can follow these steps to import existing data to custom table:

    1. Export postmeta data to CSV.
      Install the WP ALL EXPORT plugin. Export the existing ACF data, with each ACF field value corresponding to a separate column in CSV format. Additionally, include the post ID as a separate column labeled “post_id” during export.
    2. Open exported CSV and verify CSV column names with custom table columns
    3. Import this CSV into the custom table using database GUI tools like TablePlus, phpMyAdmin.
    Thread Starter Sean

    (@avidflow)

    Thank you, @abhisheksatre. Much appreciated. Also, just curious — is there a plan to include importing/migrating existing data to the newly created custom table on the roadmap?

    Plugin Author Abhishek

    (@abhisheksatre)

    Hi,

    Certainly, the migration feature is part of our future plans.

    You can use a script like the following in WP Console:

    <?php
    
    $args = [
        'post_type' => 'dealers', // Replace with your post type
        'posts_per_page' => -1,
        'fields' => 'ids',
    ];
    
    $posts = get_posts($args);
    
    // replace with your ACF field keys and names
    $fields_to_update = [
        'field_658f34acfa8b1' => 'dealer_type',
        'field_63e2523c7b2a8' => 'netsuite_id',
        'field_63bc663415a82' => 'phone',
        'field_63e16cc724134' => 'fax',
        'field_63bc664f15a83' => 'website',
        'field_63e252187b2a7' => 'website_domain',
        'field_63bc67275b5ea' => 'open_hours',
        'field_63bc7f1f02a3b' => 'location',
    ];
    
    $acf_cpt = new Acf_ct_register_hooks();
    
    $_POST['_acf_changed'] = "1";
    
    foreach ($posts as $post_id) {
        $_POST['acf'] = [];
    
        foreach ($fields_to_update as $field_key => $field_name) {
            $field_value = get_field($field_name, $post_id);
            if ($field_value !== false) {
                $_POST['acf'][$field_key] = $field_value;
            }
        }
    
        // Call the function to handle saving the post
        $acf_cpt->acf_ct_handle_save_post($post_id);
    
        // Output for confirmation
        echo "Processed post ID: {$post_id}\n";
    }

    You can find the field keys for your scenario by enabling ‘key’ under ‘Screen elements’ in the field group edit screen.

    • This reply was modified 11 months, 2 weeks ago by Kevin Shenk.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can I move Custom Post data to a Custom Table?’ is closed to new replies.