Importing data to custom table does not work
Support › MB Custom Table › Importing data to custom table does not work
- This topic has 5 replies, 2 voices, and was last updated 3 years ago by
Long Nguyen.
-
AuthorPosts
-
April 11, 2022 at 7:11 PM #35562
Robert Feddes
ParticipantI have a CPT called Reviews
I made custom field group called testimonials with 8 custom fields
I chose to Save data in a custom table called wp_custom_testies
I chose create table automatically
Then I use wp all import pro to import a csv with 200 reviews
After import I only see the titles of the added revies, none of the data is saved in the custom fields
How can I import that data from a csv properly?
Thanks
April 11, 2022 at 10:35 PM #35564Robert Feddes
ParticipantI have tried the following code, adapted from your website:
function oxygen_child_data_testimonials() { if ( empty( $_GET['move-data-testimonials'] ) || ! current_user_can( 'manage_options' ) ) { return; } $paged = isset( $_GET['oxygen-child-paged'] ) ? $_GET['oxygen-child-paged'] : 0; $paged += 1; $url = add_query_arg( 'oxygen-child-paged', $paged, 'https://www.rugpijnweg.nl/wp-admin/?move-data-testimonials=1' ); $posts = oxygen_child_admin_records_get_testimonials( $paged ); if ( empty( $posts ) ) { die( 'Done' ); } foreach ( $posts as $post ) { oxygen_child_move_data_testimonials( $post ); } echo " <script> setTimeout( () => { window.location.href = '$url'; }, 3000 ); </script> "; die; } add_action( 'admin_init', 'oxygen_child_data_testimonials' ); function oxygen_child_admin_records_get_testimonials( $paged = 1 ) { $args = [ 'post_type' => 'reviews', 'posts_per_page' => 100, 'paged' => $paged, 'fields' => 'ids', 'orderby' => 'ID', ]; $query = new WP_Query( $args ); return $query->posts; } function oxygen_child_move_data_testimonials( $post_id ) { global $wpdb; echo 'Migrating Reviews ', $post_id, '<br>'; $data = []; $data['ID'] = $post_id; $data['testie_title'] = get_post_meta( $post_id, 'testie_title', true ); $data['testie_description'] = get_post_meta( $post_id, 'meta_description', true ); $data['testie_sandwich_link_text'] = get_post_meta( $post_id, 'testie_sandwich_link_text', true ); $data['testie_linkto_text'] = get_post_meta( $post_id, 'testie_linkto_text', true ); $data['testie_header'] = get_post_meta( $post_id, 'testie_header', true ); $data['testie_slogan'] = get_post_meta( $post_id, 'testie_slogan', true ); $data['testie_text'] = get_post_meta( $post_id, 'testie_text', true ); $data['testie_name'] = get_post_meta( $post_id, 'testie_name', true ); $data['testie_key'] = get_post_meta( $post_id, 'testie_key', true ); $data['testie_rating'] = get_post_meta( $post_id, 'testie_rating', true ); $data = array_filter( $data ); if ( $data ) { $wpdb->insert( 'wp_custom_testies', $data ); } $meta_key_array = [ 'testie_title', 'testie_description', 'testie_sandwich_link_text', 'testie_linkto_text', 'testie_header', 'testie_text', 'testie_name', 'testie_key', 'testie_rating', ]; $meta_key = "'" . implode( "','", $meta_key_array ) . "'"; $wpdb->query( $wpdb->prepare( " DELETE FROM wpqq_postmeta WHERE post_id = %d AND meta_key IN ( $meta_key )", $post_id ) ); }
But nothing happens
April 11, 2022 at 11:06 PM #35565Robert Feddes
ParticipantI tried your instructions on: https://metabox.io/move-custom-fields-data-to-custom-tables/
But I am on oxygen builder, so am wondering how to do this.
I tried the following code and added it to a code snippet, and also tried it as a separate plugin, but no luck at all.
Help MUCH appreciated
function oxygen_child_data_testimonials() { if ( empty( $_GET['move-data-testimonials'] ) || ! current_user_can( 'manage_options' ) ) { return; } $paged = isset( $_GET['oxygen-child-paged'] ) ? $_GET['oxygen-child-paged'] : 0; $paged += 1; $url = add_query_arg( 'oxygen-child-paged', $paged, 'https://www.rugpijnweg.nl/wp-admin/?move-data-testimonials=1' ); $posts = oxygen_child_admin_records_get_testimonials( $paged ); if ( empty( $posts ) ) { die( 'Done' ); } foreach ( $posts as $post ) { oxygen_child_move_data_testimonials( $post ); } echo " <script> setTimeout( () => { window.location.href = '$url'; }, 3000 ); </script> "; die; } add_action( 'admin_init', 'oxygen_child_data_testimonials' ); function oxygen_child_admin_records_get_testimonials( $paged = 1 ) { $args = [ 'post_type' => 'reviews', 'posts_per_page' => 100, 'paged' => $paged, 'fields' => 'ids', 'orderby' => 'ID', ]; $query = new WP_Query( $args ); return $query->posts; } function oxygen_child_move_data_testimonials( $post_id ) { global $wpdb; echo 'Migrating Reviews ', $post_id, '<br>'; $data = []; $data['ID'] = $post_id; $data['testie_title'] = get_post_meta( $post_id, 'testie_title', true ); $data['testie_description'] = get_post_meta( $post_id, 'meta_description', true ); $data['testie_sandwich_link_text'] = get_post_meta( $post_id, 'testie_sandwich_link_text', true ); $data['testie_linkto_text'] = get_post_meta( $post_id, 'testie_linkto_text', true ); $data['testie_header'] = get_post_meta( $post_id, 'testie_header', true ); $data['testie_slogan'] = get_post_meta( $post_id, 'testie_slogan', true ); $data['testie_text'] = get_post_meta( $post_id, 'testie_text', true ); $data['testie_name'] = get_post_meta( $post_id, 'testie_name', true ); $data['testie_key'] = get_post_meta( $post_id, 'testie_key', true ); $data['testie_rating'] = get_post_meta( $post_id, 'testie_rating', true ); $data = array_filter( $data ); if ( $data ) { $wpdb->insert( 'wp_custom_testies', $data ); } $meta_key_array = [ 'testie_title', 'testie_description', 'testie_sandwich_link_text', 'testie_linkto_text', 'testie_header', 'testie_text', 'testie_name', 'testie_key', 'testie_rating', ]; $meta_key = "'" . implode( "','", $meta_key_array ) . "'"; $wpdb->query( $wpdb->prepare( " DELETE FROM wpqq_postmeta WHERE post_id = %d AND meta_key IN ( $meta_key )", $post_id ) ); }
April 12, 2022 at 12:45 PM #35577Long Nguyen
ModeratorHi Robert,
WP All Import (Pro) is not fully compatible with Meta Box extensions to import data to the custom table. You can try to contact their support to ask for help with this issue.
If you use the custom code to move data from the default table
wp_postmeta
to the custom table and are using Oxygen which ignores loading files from the theme folder, you can use the plugin Code Snippets to implement the custom code.
https://wordpress.org/plugins/code-snippets/April 12, 2022 at 12:55 PM #35579Robert Feddes
ParticipantHi Long
I added that code to code snippets, but that did not work, apparently oxygen needs different code, can you test that please?
Thanks
Robert
April 13, 2022 at 10:08 PM #35618Long Nguyen
ModeratorHi,
Please note that the article with the code above helps you to move the custom field value from the default table
wp_postmeta
to the custom table. That means the field value exists in the database.Another way, you can create a service request here https://metabox.io/contact/. Our developers will check it, estimate the job and get back to you with a quote.
-
AuthorPosts
- You must be logged in to reply to this topic.