WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

XML-RPC WordPress API/Media

wp.getMediaItem

Retrieve a media item (i.e, attachment).

Added in WordPress 3.1.

Parameters

  • int blog_id
  • string username
  • string password
  • int attachment_id

Return Values

MediaItemMetadata

  • struct
    • int width
    • int height
    • string file: The filename, including path from the uploads directory (eg "2013/09/foo.jpg")
    • struct sizes: A struct (array) of MediaItemSize objects describing each of the sizes of this media item which are available. Note that not every size exists for every media item.
      • MediaItemSize thumbnail
      • MediaItemSize medium
      • MediaItemSize large
      • MediaItemSize post-thumbnail
    • PostThumbnailImageMeta image_meta

MediaItemSize

  • struct
    • string file: The filename of this version of the media item, at this size, without the path (eg. "foo-768x1024.jpg" or "foo-940x198.jpg")
    • string width
    • string height
    • string mime-type : image/jpeg or ...

PostThumbnailImageMeta

  • struct
    • int aperture
    • string credit
    • string camera
    • string caption
    • int created_timestamp
    • string copyright
    • int focal_length
    • int iso
    • int shutter_speed
    • string title

Errors

  • 403
  • 404
    • If no attachment with that attachment_id exists.

Notes

In the MediaItemMetadata the file value includes the path from the uploads directory (usually wp-content/uploads) like "2013/09/foo.jpg" while in the MediaItemSize structs, the file value contains only the name of the file like "foo.jpg".

wp.getMediaLibrary

Retrieve list of media items.

Added in WordPress 3.1.

Parameters

  • int blog_id
  • string username
  • string password
  • struct filter: Optional (and all members are optional).
    • int number: Total number of media items to retrieve.
    • int offset
    • int parent_id: Limit to attachments on this post ID. 0 shows unattached media items. Empty string shows all media items.
    • string mime_type

Return Values

Errors

wp.uploadFile

Upload a media file.

Parameters

  • int blogid
  • string username
  • string password
  • struct data
    • string name: Filename.
    • string type: File MIME type.
    • base64 bits: binary data. Needs to be base64-encoded.
    • bool overwrite: Optional. Has no effect (see 17604). Was intended to overwrite an existing attachment of the same name. (Added in WordPress 2.2)
    • int post_id: Optional. Allows an attachment to be assigned to a post. (User must have permission to edit the assigned post)

Return Values

  • struct
    • string id (Added in WordPress 3.4)
    • string file: Filename.
    • string url
    • string type

Errors

  • 401
  • 500
    • File upload failure.