Alex
Alex

Reputation: 33

sql query: how to grab the "File URL" of every featured image in wordpress?

Which is the sql query in order to grab the "File URL"of every featured image(original image/example: http://www.mysite.com.com/wp-content/uploads/2012/photo.jpg) and add it to the beginning of the corresponding post like that example: [wide]http://www.mysite.com.com/wp-content/uploads/2012/photo.jpg[/wide]

Upvotes: 3

Views: 3186

Answers (2)

Oterox
Oterox

Reputation: 658

depending on what you want to do, the better way would be the one suggested by @Sheikh but if you want to do a different thing and need a sql query, this query get all the featured images urls:

SELECT  ( SELECT guid FROM wp_posts WHERE id = m.meta_value ) AS url 
FROM wp_posts p, wp_postmeta m
WHERE p.post_type =  'post'
AND p.post_status =  'publish'
AND p.id = m.post_id
AND m.meta_key =  '_thumbnail_id'

Remember you can use this filter too:

add_filter('the_content', 'add_post_content');

Upvotes: 5

The Alpha
The Alpha

Reputation: 146191

Inside the loop you can use

<?php

 if ( has_post_thumbnail( $post->ID ) ):
 $imgData = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) ); 
 echo $imgData[0]; // Output: featured image url
 endif; 

?>

Upvotes: 1

Related Questions