Support » Fixing WordPress » automatically convert images from media gallery to post

  • Am running a blog, each post only includes exactly 1 picture from the media folder.

    Is there a way to automate this?

    I can batch upload my images to media folder, how can I batch create post using these images just uploaded?


Viewing 1 replies (of 1 total)
  • There’s two ways you could go about this, I think…

    1. Create or use a theme that uses attachments as the primary post view. Attachments are considered posts within the database and have a place within the template hierarchy (details). If you want to go this route, take a look at WP_Query for more details on how to query posts.
    2. Hook in to the add_attachment action in WordPress. The documentation on this hook is a little sparse in the Codex, but check out this post on StackExchange for an example of how the hook can be used. In this case, when an image gets uploaded, you’ll use the hook to call a function (probably placed in functions.php of your theme or as a plugin), which will pull up the attachment info and generate a new post from that (see wp_insert_post).

    You’ll need to determine based upon your content whether using attachments as the primary post types (in a way) or creating a hook is the more appropriate solution. Both solutions will require some PHP coding (the hook solution is probably a little heavier on the PHP) – the former may also need some HTML/CSS work on the front end.

    I hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘automatically convert images from media gallery to post’ is closed to new replies.