1

I have a theme with a custom post type that is a business listing. I need to import a pack of business listings. I have written sql that adds the data to wp_posts and wp_postmeta. When I run my queries the posts show in the post edit screen in the admin but the page will not display until i press the 'update' button. The 'update' button is changing something in the db that i am missing. Are there any other tables that I would need to update?

$step1 = $wpdb->get_results('SELECT listing_id, `company name`, `primary sic description` FROM ap_listing', ARRAY_A);

foreach($step1 as $s1){
    $pname = $s1['company name'];
    $pname = str_replace(" ", "-", $pname);

    $wpdb->insert( wp_posts, 
        array(
            'listing_idp' => $s1[listing_id],
            'post_title' => $s1['company name'],
            'post_name' => $pname,
            'post_content' => $s1['primary sic description'],
            'post_status' => 'publish',
            'post_type' => 'item',
            'comment_status' => 'closed',
            'ping_status' => 'closed',
            'post_author' => '2',
            'post_date' => '2016-10-13 14:07:04',
            'post_date_gmt' => '2016-10-13 19:07:04',
            'post_modified' => '2016-10-13 14:07:04',
            'post_modified_gmt' => '2016-10-13 19:07:04'
        )
    );




    $guid1 = 'http://spfpxnew.staging.wpengine.com/?post_type=item&p=';
    $guid2 = $wpdb->get_results("SELECT id FROM wp_posts WHERE listing_idp = $s1[listing_id]", ARRAY_A);
    $guid2 = $guid2[0][id];
    $fix_guid = $guid1 . $guid2;

    $wpdb->update( wp_posts, 
        array( 'guid' => $fix_guid ),
        array( 'id' => $guid2 )
    );
}

//post_title post_name guid post_content post_type
//http://spfpxnew.staging.wpengine.com/?post_type=item&p=6
$step2 = $wpdb->get_results('SELECT id, listing_idp FROM wp_posts', ARRAY_N);

foreach($step2 as $s2){
    if($s2[1] != ''){
        echo ' '.$s2[0].' '.$s2[1];
        $wpdb->update( ap_listing, 
            array(
                'id' => $s2[0]
            ),
            array( 'listing_id' => $s2[1] ) 
        );
    }
}
////////

$step3 = $wpdb->get_results('SELECT id, address, city, state, `zip code`, `web address`, `phone number` FROM ap_listing', ARRAY_A);


foreach($step3 as $s3){
    $s3zip = substr($s3['zip code'],0,5);
    $address = $s3[address].', '.$s3[city].', '.$s3[state].' '.$s3zip;
    $phone_number = $s3['phone number'];
    $web_address = $s3['web address'];


$wpdb->query("INSERT INTO wp_postmeta
                (post_id, meta_key, meta_value)
            VALUES
                ($s3[id], 'jv_item_address', '$address'),
                ($s3[id], 'jv_item_phone', '$phone_number'),
                ($s3[id], 'jv_item_website', '$web_address'),
                ($s3[id], 'jv_item_lat', '33.0415765'),
                ($s3[id], 'jv_item_lng', '-96.71691829999997'),
                ($s3[id], 'javo_control_options', ''),
                ($s3[id], 'javo_slider_type', ''),
                ($s3[id], 'javo_posts_per_page', ''),   
                ($s3[id], 'javo_item_tax', 's:17:\"a:1:{i:0;s:0:\"\";}\";'),
                ($s3[id], 'javo_blog_tax', ''),
                ($s3[id], 'javo_item_terms', 's:2:\"N;\";'),
                ($s3[id], 'javo_blog_terms', 's:2:\"N;\";'),
                ($s3[id], '_vc_post_settings',  'a:1:{s:10:\"vc_grid_id\";a:0:{}}'),
                ($s3[id], '_edit_lock', '1476225539:2'),
                ($s3[id], '_edit_last', '3'),
                ($s3[id], 'javo_this_featured_item', ''),
                ($s3[id], 'jv_item_email', ''),
                ($s3[id], 'jv_item_street_lat', '32.78092141476407'),   
                ($s3[id], 'jv_item_street_lng', '-97.29449262685023'),
                ($s3[id], 'jv_item_street_heading', '0'),
                ($s3[id], 'jv_item_street_pitch', '0'),
                ($s3[id], 'jv_item_street_zoom', '1.0000000000000002'),
                ($s3[id], 'video', ''),
                ($s3[id], 'detail_images', 's:2:\"N;\";'),
                ($s3[id], 'header_custom_frame', ''),
                ($s3[id], 'item_map_positon', 's:6:\"a:0:{}\";'),
                ($s3[id], 'item_map_type', 's:6:\"a:0:{}\";'),
                ($s3[id], 'rating_average', '0.0'),
                ($s3[id], 'rating_meta', 'a:3:{s:5:\"total\";i:0;s:5:\"count\";i:0;s:7:\"average\";s:3:\"0.0\";}'),
                ($s3[id], 'slide_template', 'default'),
                ($s3[id], 'id5d4b82bf8ac903deb7f1f2e0bffd8afd', '|'),
                ($s3[id], 'id760f1150c15bf1468167d6da636782b5', ''),
                ($s3[id], 'ide8fdcf7960dd73144a1b8c10b9472fcb', ''),
                ($s3[id], 'id1d5e239e8dd52aeec7d0cf048655fa94', ''),
                ($s3[id], 'idd979148b7f50be8daf3690ec24689468', 'one-basic'),
                ($s3[id], 'iddda96d13c08720696764b65c4e4ab1e8', '|'),
                ($s3[id], 'hours', ''),
                ($s3[id], '_hours', 'field_57a8ba1d84241'),
                ($s3[id], '_', 'field_57a8ba7584242'),
                ($s3[id], 'monday', ''),
                ($s3[id], '_monday', 'field_57a8c712e71f0'),
                ($s3[id], 'tuesday', ''),
                ($s3[id], '_tuesday', 'field_57a8ccb2df031'),
                ($s3[id], 'wednesday', ''),
                ($s3[id], '_wednesday', 'field_57a8ccb2df030'),
                ($s3[id], 'thursday', ''),
                ($s3[id], '_thursday', 'field_57a8ccb1df02f'),
                ($s3[id], 'friday', ''),
                ($s3[id], '_friday', 'field_57a8ccb1df02e'),
                ($s3[id], 'saturday', ''),
                ($s3[id], '_saturday', 'field_57a8ccaedf02d'),
                ($s3[id], 'sunday', ''),
                ($s3[id], '_sunday', 'field_57a8cca7df02c'),
                ($s3[id], 'id2a4db98f077d53cf4174811e3c0bc545', '|'),
                ($s3[id], '_thumbnail_id',  ''),
                ($s3[id], 'id0f0959cbade4391cb8a30aef3eb57204', ''),
                ($s3[id], 'id9748bd65165e381e97385e1b5da02eab', ''),
                ($s3[id], 'id4be8dc375419760b821506f6a910d839', ''),
                ($s3[id], 'id80b7c6af2fb8b382b30af29bd0173b1c', ''),
                ($s3[id], 'id27daa11ffa9b4d39eba88be248c2b6f2', ''),
                ($s3[id], 'idd74cc17ebbcaeaa64521e8348658aaff', ''),
                ($s3[id], 'idb87e03157e07dcac499c8abcb7f6fc62', '')
            ");

}
1
  • 1
    Use WordPress higher level functions for saving posts and meta. They'll look after everything for you. Commented Oct 13, 2016 at 20:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.