require_once( ABSPATH . 'wp-admin/includes/image.php' ); $handle = fopen(ABSPATH . 'portfolio.csv', 'r'); $matches_array = []; $post_array = []; $acf_array = [ 'face' => 'field_592181d33213f', 'razd' => 'field_5921822a32140', 'menu' => 'field_5921825f32141', 'top' => 'field_592186dd32142', 'slide' => 'field_592186dd32142', 'big' => 'field_5921871232143' ]; $exibit_field = 'field_592b7ff6bb8de'; $diploma_field = 'field_592b7fabbb8da'; $images = []; $specs_array = []; $cur = $_GET['offset'] ? $_GET['offset'] : 0; $row = 0; $it = new RecursiveDirectoryIterator(get_template_directory().'/images/photo/'); // fseek($handle,$cur); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { /* * * TAXONOMY IMPORT * * */ // $parent_term = term_exists( $data[2], 'category' ); // array is returned if taxonomy is given // $parent_term_id = $parent_term['term_id']; // get numeric term id // wp_insert_term( // $data[2], // the term // 'category', // the taxonomy // array( // 'description'=> 'cat_'.$data[0], // 'slug' => $data[6], // 'parent'=> $parent_term_id // ) // ); /* * * END TAXONOMY IMPORT * */ $id_raw = array_unique(explode(' ',$data[1])); $id = str_replace('cat_','',$id_raw[0]); // if(array_key_exists($id,$specs_array)){ // $cur_spec = $specs_array[$id]; // }else { // // $post = new WP_Query([ // 'post_type' => 'spec', // 'meta_key' => 'old_id', // 'meta_value' => $id, // 'meta_compare' => '=' // ]); // $cur_spec = $post->post; // } $post = new WP_Query([ 'post_type' => 'portfolio', 'meta_key' => 'old_id', 'meta_value' => $id, 'meta_compare' => '=' ]); $cur_spec = $post->post; // $post = new WP_Query([ // 'post_type' => 'services', // 'title' => $data[9], // 'post_status' => 'any' // ]); // $cur_spec = $post->post; // echo '
';
//    print_r(get_field($diploma_field,$cur_spec->ID));
//    echo '
'; //update_field($diploma_field, [], $cur_spec->ID); //if($cur_spec) { // $id = wp_insert_post([ // 'post_title' => $data[9], // 'post_excerpt' => $data[10], // 'post_content' => $data[11], // 'post_type' => 'vacancies', // 'post_status' => ($data[7] == '0') ? 'publish' : 'draft', // 'post_name' => str_replace('.html', '', $data[15]) // ] // ); // // // seo add // update_post_meta($id, '_aioseop_description', $data[18]); // update_post_meta($id, '_aioseop_title', $data[16]); // update_post_meta($id, '_aiosp_keywords', $data[17]); // update_post_meta($id, 'old_id', $data[0]); // update_field('field_593098ad10a11', $data[26], $id); // $specs_array[$id] = $data[0]; // // wp_update_post( // array ( // 'ID' => $cur_spec->ID, // 'post_name' => str_replace('.html','',$data[15]) // ) // ); //update_field('field_592c9029d6e0f',$data[24],$id); // $term = $wpdb->get_results( // "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.description in (".implode(',',array_filter(array_map(function($item){ if(strlen($item) > 1) return "'$item'"; },explode(' ',$data[13])))).")", // ARRAY_A // ); // $terms = array_map(function($item){ // return $item['slug']; // },$term); // wp_set_object_terms( $id, $terms, 'category' ); // // foreach (new RecursiveIteratorIterator($it) as $file) { if (strpos($file, '/'.$data[3]) > -1) { $images[] = $file; } } if ($images) { foreach ($images as $k => $i) { $filetype = wp_check_filetype(basename($i), null); $file_url = str_replace(get_template_directory(), get_template_directory_uri(), $i); $upload_file = wp_upload_bits($i, null, file_get_contents($file_url)); $title = preg_replace('/\.[^.]+$/', '', basename($i)); $attachment = array( 'guid' => $file_url, 'post_mime_type' => $filetype['type'], 'post_title' => $title, 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $upload_file['file'], $cur_spec->ID); $attach_data = wp_generate_attachment_metadata($attach_id, $upload_file['file']); wp_update_attachment_metadata($attach_id, $attach_data); // clean title to find correct place // preg_match('/(.*)\-/', $title, $matches); // if(array_key_exists($matches[1],$acf_array)) // update_field($acf_array[$matches[1]],$attach_id,$id); // $val = get_field($diploma_field, $cur_spec->ID) ? get_field($diploma_field, $cur_spec->ID) : []; // $val[] = ['title' => $data[9], 'desc' => $data[11], 'img' => $attach_id]; // update_field($diploma_field, $val, $cur_spec->ID); //$val[$cur_spec->ID][] = ['title' => $data[9], 'desc' => $data[11], 'img' => $attach_id]; unset($i); //unset($val); unset($images[$k]); } unset($images); } if ($row == 3) { // foreach($val as $k=>$i){ // $v = get_field($diploma_field,$k) ? get_field($diploma_field,$k) : []; // update_field($diploma_field, array_merge($v,$i), $k); // } header('Location: http://wp.cogerent.ua/%D0%B8%D0%BC%D0%BF%D0%BE%D1%80%D1%82.html?offset=' . ftell($handle)); exit(); } else { $row++; } //} } fclose($handle); // //$handle = fopen(ABSPATH . 'services.csv', 'r'); //while (($data_1 = fgetcsv($handle, 1000, ",")) !== FALSE) { // if($data_1[2] !== '0'){ // wp_update_post(['ID'=>$matches_array[$data_1[0]],'post_parent'=>$matches_array[$data_1[2]]]); // } //} //fclose($handle);