arunvkumarkc

Insert query

Nov 8th, 2012
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. require_once('csv.php');
  3. require_once('wp-load.php');
  4. $csv = new parseCSV();
  5.  
  6. $csv->limit = 50;
  7. $csv->auto('cs/4.csv');
  8. echo "<pre>";
  9. //print_r($csv->data);
  10. $i=0;
  11. foreach ($csv->data as $val) {
  12.     $title = ucfirst( sanitize_text_field ($val['title'] ) );
  13.     $address_line1 = ucfirst( sanitize_text_field( $val['address_line1'] ) ) ;
  14.     $breed = ucfirst( sanitize_text_field( $val['breed'] ) ) ;
  15.     $email = sanitize_text_field( $val['email'] ) ;
  16.     $website = sanitize_text_field( $val['website'] );
  17.     $phone = sanitize_text_field( $val['phone'] );
  18.     $country = ucfirst( sanitize_text_field( $val['country'] ) );
  19.     $city = ucfirst( sanitize_text_field( $val['city'] ) );
  20.     $state = ucfirst( sanitize_text_field( $val['state'] ) );
  21.     $zip = sanitize_text_field( $val['zip'] );
  22.     if( $address_line1 == "") {
  23.         $address_line1 = $zip." ".$city." ".$state." ".$country;
  24.     }
  25.     if( $title != "" && strtolower($country) == "usa" && strlen($state)>3) {
  26.         $guide_profile['post_title']    = $title;
  27.         $guide_profile['post_type']     = 'puppycheck';
  28.         $guide_profile['post_content']  = '';
  29.         $guide_profile['post_status']   = "publish";
  30.  
  31.         $guide_profile_meta['gms_location_name'] = $address_line1;
  32.         $guide_profile_meta['cnumber1']          = $phone;
  33.         $guide_profile_meta['gr_email']          = $email;
  34.         $guide_profile_meta['gr_web_url']        = $website;
  35.         $guide_profile_meta['gprofile_zip']      = $zip;
  36.         $guide_profile_meta['gprofile_species']  = $breed;
  37.  
  38.         $guide_profile_meta['businessownerprofile'] = "no";
  39.         $guide_profile_meta['displaymap']           = "no";
  40.         $guide_profile_meta['importedprofile']      = "yes";
  41.         echo ++$i." ** ";
  42.         $wp_error =  true;
  43.         echo $guide_postid  = wp_insert_post( $guide_profile, $wp_error );
  44.         echo "<br>";
  45.         if( !is_wp_error ( $guide_postid ) ) {
  46.  
  47.             /*$custom_field_keys = array ();
  48.             $custom_field_keys = get_post_custom_keys( $guide_postid );
  49.             $custom_field_keys[] = 'testcustomfield';*/
  50.             foreach( $guide_profile_meta as $gpm_key => $gpm_value ) {
  51.                
  52.                     add_post_meta($guide_postid, $gpm_key, $gpm_value, true );
  53.             }
  54.  
  55.             //Inserting the state values
  56.             if( $state != "" ){
  57.                 $terms = array();
  58.                 $terms[0] = 'Usa';
  59.                 $terms[1] = $state;
  60.                 $taxonomy = 'puppycheckcategory';
  61.                 $append = false;
  62.                 wp_set_object_terms ( $guide_postid, $terms, $taxonomy , $append  );
  63.             }
  64.            
  65.             //Inserting the category values
  66.             $terms = array();
  67.             $taxonomy = 'puppychecktags';
  68.             $append = false;
  69.             $terms = array('Breeder');
  70.             wp_set_object_terms ( $guide_postid, $terms, $taxonomy , $append  );   
  71.         }
  72.     }
  73. }
  74. $csv = null;
  75. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×