Where is stored the path of posts images in Wordpress?

Asked

Viewed 2,752 times

4

I am building a plugin in cakephp custom, because the wordpress plugin itself does not work, until then, I managed to use everything, from the wordpress posts table, the problem is that I do not know where is the path of the posts images. Thank you in advance.

1 answer

4


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?

  • @Michelhenriq takes a look at the edited response

  • 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?

  • Inside wordpress you can use <?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );&#xA;echo $thumb['0']; ?>

  • 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.

  • you having the post id just give a select in the table postmeta with the post_id of your post and the meta_key with _wp_attached_file, it will return something like 2015/11/img.jpg then just add the wp-content/uploads/ before and was

  • I don’t understand where this comes in _wp_attached_file. It is a wordpress function?

  • select * from postmeta where post_id = 168 and meta_key = "_wp_attached_file"

  • I ran this query in my database and returned zero

  • 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)

  • _wp_attached_file is image and _wp_attachment_metadata is the content of the post?

  • _wp_attached_file is the file name with address from the wp-content/uploads/ and the _wp_attachment_metadata as the very termination in meta suggests are information about this image, eg: width, height, mime type among several others.

  • 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..

  • How can I tell posts from image uploads?

  • 1

    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.

  • and how I echo this query?

Show 12 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.