pods_attachment_import

Import media from a specific URL, saving as an attachment

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.';
}

 

Other Helpful Documentation on Media Functions

pods_image

Get the  HTML for a specific image field

pods_image_id_from_field

Get the Attachment ID for a specific image field

pods_image_resize

Resize an image on demand

pods_image_url

Get the Image URL for a specific image field