I know how to upload multiple images into an existing post, but this is a different scenario. This is for a large catalog of assets, with each custom post-type post representing an image asset (thus a single image is assigned as the “featured image” for each post).
The whole system works great for one-at-a-time asset creation, but far too time-consuming. I need to be able to “batch” upload multiple images at once, then have a new post created for each image, then attach the image to the new post as the “featured image”.
There will be no text content entered for each post – just some metadata and custom taxonomy assignments, so it should be possible to batch-assign the metadata and taxonomy during this batch creation process.
I’ve researched solutions from XML-RPC post creation (which doesn’t usually handle image upload/assignment) to plugins that pull files from a server directory to the media library (which doesn’t cover post creation), and jquery multiple file uploaders (that basically just dump files in a directory).
I am relatively versed in php, having built plugins and themes, but I’m stumped at how to handle this process, as it requires the first step of getting the files to the server in some temporary capacity, then generating posts based on the files uploaded, and assigning some identifying metadata to the whole batch.
I’m hoping this can be done in a custom admin panel, but if I have to do this outside of wp-admin, that’s fine too…
Ideas?
There is this plugin: Automatic Featured Image Posts Plugin
From the plugin page:
Basically, every image that is uploaded generates a post (of your chosen post-type) and is set as the featured image of that post.
I installed this on my local machine. The settings page looks like this and allows you to select which post type, including custom post types, you want to assign photo uploads to, and what publish status you want.
To put the plugin into practice – navigate to your chosen post type, open a new post and upload media.
To bulk upload photos, simply highlight multiple photos in the “upload” dialogue box. I’m highlighting 8 photos here, but I see no reason why it couldn’t be 80 or 800, unless there are limits I don’t know about in the wordpress image uploader.
The titles of the posts are set by the image file names. You should be able to work with that and call them in your theme with
the_title()
I tested locally and it’s working in WordPress 3.6.
I’m sure there is a more robust or flexible way to accomplish this, but in this case, the plugin seems to do exactly what you’re asking, with the exception of assigning meta-data. Maybe someone else could flesh that part out a little bit.
If you needed dynamically generated post content, you could at least start with the plugin and iterate from there. One thought there would be to use post-formats or page-templates to determine how the posts are displayed.
Note: Make sure you have all your
image_size
s set in functions.php. I’d hate to have to undo / delete 10,000 photos, or run an extremely long “regenerate thumbnails” just because I forgot or changed the image size!This script is a proof of concept (tested and working), it is not a plugin and is meant to be hacked with, it assumes a few things:
wp_insert_post
so it’s advised you do not hook it into any admin hooks, so just run it once!wp-contentuploads
folder, changing this would require more hoops to jump through. The example uses a custom folder calledimages
in the uploads folder, you can change this part.The code below will iterate through the
wp-contentuploadsimages
folder and create a post title based on the name of the image being attached to it. You probably want to change this to something better or possible enter meta data using other data you have (Exif maybe).For anything over a few thousand images you would probably have an easier time using:
comes out
The “Cleanup uploads folder, Media Library db structure” Question has some plugin suggestions that might be related – albeit not exactly that doing what you ask for. But maybe the information is useful.