Last active
March 2, 2022 11:07
-
-
Save encoderit-arman/32b1783b8196af7e95e29d30d705d130 to your computer and use it in GitHub Desktop.
Save image from remote url with wordpress, Save image from csv with wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$post_id = wp_insert_post($array);//create new post and save its id | |
$img = media_sideload_image( $url, $post_id);//download image to wpsite from url | |
$img = explode("'",$img)[1];// extract http.... from <img src'http...'> | |
$attId = attachment_url_to_postid($img);//get id of downloaded image | |
set_post_thumbnail( $post_id, $attId );//set the given image as featured image for the post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment