Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 498
Davey Avatar asked Jan 23 '11 20:01

Davey


People also ask

How do I view all images in WordPress?

You can view all your uploads under Media » Library page. From here, you can also edit these files, manipulate them, or even delete them. The specific folder where the image files are stored in WordPress is called the uploads folder located inside the /wp-content/ folder.

Does WordPress store images in database?

Wondering where does WordPress store images in the database? All the image files that you upload are also stored in the database of your site. You can view them in the Post table as an attachment. Deleting the database files will display error on the Media section of your WordPress admin backend.

Where are media files stored in WordPress database?

Where are your media files stored? Your media files are uploaded to the /wp-content/uploads/folder. Normally, the image is also placed inside a folder the month it was uploaded.


1 Answers

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.

like image 78
RichardTheKiwi Avatar answered Sep 30 '22 04:09

RichardTheKiwi