The files are in wp-content/uploads/
In the database:
As highlighted images are saved in the table postmeta
with the meta_key
of _wp_attached_file
and related to meta_key
of _thumbnail_id
As images from inside the post has the name saved in the table itself posts
together with the content in post_content
An example query to list posts with the highlighted image is:
select *, (select p.guid from wp_postmeta pm, wp_posts p where pm.meta_key="_thumbnail_id" and pm.post_id=post.id and p.ID=pm.meta_value) as imagem_destacada from wp_posts post where post_status='publish' and post_type="post";
right, but where do I get the name of the pictures?
– Michel Henriq
@Michelhenriq takes a look at the edited response
– Alan Rezende
I did a fingernail search by passing the id of the post, but it did not bring the name of the image, there is a function that works on top of meta_key?
– Michel Henriq
Inside wordpress you can use
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );
echo $thumb['0']; ?>
– Alan Rezende
Here’s the problem, I’m developing a custom plugin inside cakephp, and I can’t use the wp functions in cakephp, so I’m doing the recursive of everything to see how it works, because I need to mount these images in my hand.
– Michel Henriq
you having the post id just give a select in the table
postmeta
with thepost_id
of your post and themeta_key
with_wp_attached_file
, it will return something like2015/11/img.jpg
then just add thewp-content/uploads/
before and was– Alan Rezende
I don’t understand where this comes in
_wp_attached_file
. It is a wordpress function?– Michel Henriq
select * from postmeta where post_id = 168 and meta_key = "_wp_attached_file"
– Alan Rezende
I ran this query in my database and returned zero
– Michel Henriq
Make sure to check if the postmeta table has no prefixes ex
wp_postmeta
, and put the id of a post that contains the highlighted image (thumbnail)– Alan Rezende
_wp_attached_file
is image and_wp_attachment_metadata
is the content of the post?– Michel Henriq
_wp_attached_file
is the file name with address from thewp-content/uploads/
and the_wp_attachment_metadata
as the very termination inmeta
suggests are information about this image, eg: width, height, mime type among several others.– Alan Rezende
got it, so in case, if I want to get the last 3 posts inserted that have image just make a Join passing the criterios..
– Michel Henriq
How can I tell posts from image uploads?
– Michel Henriq
Exactly that, in the table of posts you filter the items you want by
post_type
,post_status
, etc... but this already deserves a new question not to escape the scope of the current question.– Alan Rezende
Let’s go continue this discussion in chat.
– Michel Henriq
and how I echo this query?
– Evandro Aguiar