How does one create a post, assign it to a category, add tags to it and set the featured image from a PHP script that exists somewhere on disk (say /usr/local/process.php) and isn't part of the Wordpress installation or infrastructure?

I searched for a couple of hours and can't find anything particularly useful. The only thing I'm stuck on is how to create the POST and add its metadata. The rest (like getting the images, extracting the caption etc) is already done.


I'd like to automate the process to create posts for images I have. Unlike traditional import stuff, I'd like to replace images and update their posts and metadata if they already exist. The latter is important since I manage all my image metadata in Aperture. Every image has a unique name in the form of AAA99999999 and versions (such as a B&W and cropped) of images may have the format "AAA99999999 - Version NNN". If possible, I'd like to indicate that the posts of say "AAA99999999" and "AAA99999999 - Version 1" are related. I have about 2000 photos I'd like to import.

I'd like to use the script in the future to add and update new images.

1 Answer 1


You can remotely create posts programmatically via XML-RPC

e.g. PHP




Of note, the media library handles image EXIF data etc, it might be more convenient to switch from using posts to just displaying the latest uploaded attachments that do not have a parent post (attachments with a parent post are attached to a post or in a gallery)

  • There are some limitations using XML-RPC with the version of Wordpress I have installed. In addition, the metadata library sucks at IPTC information. The keywords, location and much more isn't extracted or searchable. Further, EXIF dates when the photos were taken doesn't seem to be extracted.
    – bloudraak
    Apr 5, 2012 at 18:37
  • You can extend the XML-RPC APIs, see here for how: kovshenin.com/2010/custom-xml-rpc-methods-in-wordpress you can use these to implement the postmeta additions you need
    – Tom J Nowell
    Apr 5, 2012 at 18:40
  • Also image attachments tend to have a tertiary post added that has the original attachment as a post_parent. This tertiary posts sole purpose is to hold additional metadata
    – Tom J Nowell
    Apr 5, 2012 at 18:40
  • Here's how to add custom fields wordpress.org/support/topic/…
    – Tom J Nowell
    Apr 5, 2012 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.