Find all images in a WordPress table

Is there a mysql query that can pull all images from a table? Could not find a solution. Thanks

e. from wordpress

All images are in the wp_posts table

In my wp_posts table, all images are mixed with other data. I would like to get all the images from this table for storage on my hard drive

+4
source share
2 answers

All records from the table

SELECT * FROM tbl 

In 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 entry that it is associated with if you need some kind 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'm not mistaken, filepath gives you a link to the place on disk where the image files are actually stored. If that's all you need, just go to it (or ftp if it is deleted) and grab all the files from there.

+16
source

I am not familiar with wordpress, but once I had to do a similar thing and solve it with regular expressions.

I do not know how to do this directly in the request. I filtered the html code with regular expressions to get only parts of the img tags. I had to query all messages and then filter them.

I assume you want to extract <img /> tags from posts?

Otherwise, you should provide more information, as middaparka has already commented.

0
source

Source: https://habr.com/ru/post/1336705/


All Articles