Importing Single Images

Image fields allow the user to specify a single image URL or file path.

Rapid Add-On will automatically place the specified image in the Media Library, and pass the ID of the media to the registered import function.

$my_addon->add_field( 'property_featured_img', 'Property Featured Image', 'image' );


Your add-on’s import function will be passed the image data as an array. The ID of the image will be passed as the “attachment_id” array key.

Here’s how to set the Featured Image/Post Thumbnail to the specified image.

This example assumes the field slug specified in add_field is “property_featured_img”.

function your_import_function( $post_id, $data, $import_options ) {
	$attachment_id = $data['property_featured_img']['attachment_id'];
	set_post_thumbnail( $post_id, $attachment_id );
}

Importing Multiple Images


You can add entire image sections, with all of the settings and features that the default image section has, using the import_images() function.

$my_addon->import_images( 'property_images', 'Property Images' );

Just like with single image imports, this will call the property_images() function every time an image is imported.

Some themes allow users to upload files like PDFs. You can enable another section, identical to the default image section, except that it will allow any file type to be imported and attached to the post.

$my_addon->import_files( 'property_attachments', 'Property Attachments' );