Import media from a specific URL, saving as an attachment
Function Definition
function pods_attachment_import ( $url, $post_parent = null, $featured = false )
Source File: /pods/includes/media.php , Since 2.3
Parameters
PARAMETER | TYPE | DETAILS |
---|---|---|
$url | (string) | URL to media for import |
$post_parent | (int) | ID of post parent, default none |
$featured | (boolean) | Whether to set it as the featured (post thumbnail) of the post parent |
Returns
(int) Attachment ID
Example
$pod = pods( 'your_pod' ); // Set to the URL of your image. $url_of_image = 'http://placekitten.com/400/600'; // Import the image into WordPress. $attachment_id = pods_attachment_import( $url_of_image ); // Image was imported, we can use it now. if ( $attachment_id ) { $data = array( 'post_title' => 'My item', 'my_image' => $attachment_id ); $pod->add( $data ); } else { // Display an error if you want. echo 'Image not imported, try again.'; }