WordPress – wp_insert_post with resized post thumbnail

I will crawl some data from an XML file and I have all the information I need including the image URL.

There is a function in WordPress called wp_insert_post which is used to create posts programmically. So far, so good. Simple to use:

Read More

http://codex.wordpress.org/Function_Reference/wp_insert_post

What I also need is:

  • Add an image attached to the post thumbnail by its image URL (for example http://www.test.com/my-image.jpg)
  • Resize it on upload with WordPress built in functions (for example max 300 x 300, like medium thumbnail settings

Related posts

Leave a Reply

1 comment

  1. You can use this function for that.

    media_sideload_image($url,$post_id,$description);
    

    There is a post about this here.

    And in the theme you can use this function for getting the thumb in required size

    <?php echo get_the_post_thumbnail( $id, $size, $attr ); ?> 
    

    Read more at codex

    Default thumbnail sizes also can be changed, see this.