Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dr_cd_save_thumbnails();
- function dr_cd_save_thumbnails(){
- $wp_query = query_posts(array(
- 'post_type' => 'issue',
- 'posts_per_page' => '-1'
- ));
- // the loop
- if (have_posts()) : while (have_posts()) : the_post();
- //Companies
- $daID = get_the_ID();
- $path = get_post_meta($daID, "toc_cover_image", true);
- $fixpath = explode('/',$path);
- $datfile = 'http://digitalrelativity.net/wp-content/uploads/'.$fixpath[2].'/'.$fixpath[3].'/'.$fixpath[4];
- dr_cd_set_featured_image($daID,$datfile);
- sleep(.5);
- echo $datfile . '<br>';
- endwhile;
- endif;
- wp_reset_query();
- }
- function dr_cd_set_featured_image($post_id,$filename) {
- $wp_filetype = wp_check_filetype(basename($filename), null );
- $attachment = array(
- 'post_mime_type' => $wp_filetype['type'],
- 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
- 'post_content' => '',
- 'post_status' => 'inherit'
- );
- $attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
- echo $attach_id;
- // you must first include the image.php file
- // for the function wp_generate_attachment_metadata() to work
- require_once($_SERVER['DOCUMENT_ROOT'] . "/wp-admin" . '/includes/image.php');
- $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
- echo '<pre>';
- var_dump( $attach_data);
- echo '</pre>';
- if (wp_update_attachment_metadata( $attach_id, $attach_data )) {
- // set as featured image
- return update_post_meta($post_id, '_thumbnail_id', $attach_id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement