Ready to get started?Download WordPress


If image exists dont regenerate (1 post)

  1. toto
    Posted 2 years ago #

    Hi folks, im using from code to insert 1000 images with:

    $wp_filetype = wp_check_filetype( basename( $dest ), null );
        				$attachment = array(
                            'guid' => $filepath,
        					'post_mime_type' => $wp_filetype['type'],
        					'post_title' => preg_replace('/\.[^.]+$/', '', basename( $dest ) ),
        					'post_content' => '',
        					'post_status' => 'inherit',
        				$attach_hit_id = wp_insert_attachment( $attachment, $dest, $post_id );
        				// you must first include the image.php file for the function wp_generate_attachment_metadata() to work
        				require_once(ABSPATH . "wp-admin" . '/includes/image.php');
        				$attach_data = wp_generate_attachment_metadata( $attach_hit_id, $dest );
        				wp_update_attachment_metadata( $attach_hit_id,  $attach_data );

    Is there a way if image exists wp_generate_attachment to create only in db the image info and dont copy or regenerate images in uploads?

Topic Closed

This topic has been closed to new replies.

About this Topic