Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'init', function() {
- if ( 'migrate' !== filter_input( INPUT_GET, 'action' ) ) {
- return;
- }
- $query = new WP_Query( [
- 'posts_per_page' => -1,
- 'post_type' => 'post',
- 'post_status' => 'any',
- ] );
- if ( ! $query->have_posts() ) {
- return;
- }
- global $wpdb;
- $table_name = 'your_table';
- while ( $query->have_posts() ) {
- $query->the_post();
- $field_id_1 = 'image_26';
- $field_value_1 = get_post_meta( get_the_ID(), $field_id_1, false ); // Image field store multiple values.
- $field_id_2 = 'text_1';
- $field_value_2 = get_post_meta( get_the_ID(), $field_id_2, true ); // Text field store a single value.
- $data = [
- 'ID' => get_the_ID(),
- $field_id_1 => serialize( $field_value_1 ),
- $field_id_2 => $field_value_2,
- ];
- $wpdb->delete( $table_name, ['ID' => get_the_ID()] ); // Delete existing data.
- $wpdb->insert( $table_name, $data ); // Insert data to the table.
- }
- } );
Add Comment
Please, Sign In to add comment