Find all Images in WordPress Table

Is there a mysql query that can pull all of the images out of a table? Haven’t had any luck finding a solution. Thanks

e. from a wordpress site

Read More

The images are all in the wp_posts table

In my wp_posts table all of the images are mixed in with other data. I would like to get all of the images out of this table to store on my hard drive

Related posts

Leave a Reply

2 comments

  1. All records from a table

    SELECT * FROM tbl
    

    From a specific table

    SELECT * FROM wp_posts
    

    Based on WordPress Database ERD, to get attachments, this should be close

    SELECT * FROM wp_posts
    WHERE post_type='attachment' and post_status='inherit'
    

    This will give you the attachments as well as the parent post it related to, if you need some sort of context

    SELECT 
      posts.ID,
      posts.post_title AS title,
      posts.post_content AS content,
      files.meta_value AS filepath
    FROM
      wp_posts posts
      INNER JOIN wp_posts attachments ON posts.ID = attachments.post_parent
      INNER JOIN wp_postmeta files ON attachments.ID = files.post_id
    WHERE files.meta_key = '_wp_attached_file'
    

    If I am not mistaken, the filepath gives you a link to a disk location where the image files are actually stored. If that is all you want, just browse to it (or ftp if remote) and grab all files from there.

  2. I’m not familiar with wordpress but I once had to do a similar thing and solved it via regular expressions.

    I do not know a way of doing this directly in the query. I filtered the html code with regular expressions so as to obtain only the img-tags parts. I had to query all posts and then filter them.

    I’m assuming you are looking to extract the <img /> tags from the posts?

    Otherwise you should provide more info as middaparka already commented.