Importing data to custom table does not work

Support MB Custom Table Importing data to custom table does not work

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #35562
    Robert FeddesRobert Feddes
    Participant

    I 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

    #35564
    Robert FeddesRobert Feddes
    Participant

    I 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

    #35565
    Robert FeddesRobert Feddes
    Participant

    I 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
    	) );
    }
    #35577
    Long NguyenLong Nguyen
    Moderator

    Hi 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/

    #35579
    Robert FeddesRobert Feddes
    Participant

    Hi 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

    #35618
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.