Skip to content
Ajit Bohra edited this page Jun 28, 2017 · 11 revisions

Use this field to create allow image uploads.

This field invokes the native WordPress Media Upload. It thereby supports selecting directly from the Media Library, or adding to it via drag/drop. It defaults to the Media Library tab of the uploader.

The value saved is the attachment id.

image

Args

Required Args

  • id (string) (required)
  • name (string) (required) Field display name. Used as field label.
  • type 'image' (required)

Field Specific Args

  • size (string) (optional) - Set display size and crop within the metabox
    • Example: 'height=100&width=100&crop=1'
  • show_size (bool) (optional) - Display size dimensions in an empty image field.
  • library-type (array) (optional) - By default the image field only includes 'image' other file types can be passed
    • Example: 'library-type' => array('image', 'video', 'audio', 'text', 'application' )

Optional Generic Args

See Optional Generic Args

Example Usage

array( 
	'id'   => 'example-field-image', 
	'name' => 'An image input', 
	'type' => 'image', 
),

Displaying Uploaded Image

$image_id = get_post_meta( $my_post_id, 'my-image-meta-id', true );  // Get image ID.
$url = wp_get_attachment_url( $image_id ); // Get the URL only.
wp_get_attachment_image( $image_id );  // Get a full image tag.