Automatically set the featured image
Method 1: Using the publish_post hook* and media_sideload_image() Here we will upload an image from a URL, attach it to the post, and set it as the featured image when the post is published. *Actually, we’re using the dynamic hook {$new_status}_{$post->post_type}, which refers transitioning a post post type to the publish status. See wp-includes/post.php for … Read more