Reputation: 4425
I am trying to get media attached to the post in WP like this¨
if (have_posts()) : while (have_posts()) : the_post(); ?>
$images = get_attached_media('image');
What I have observed is that when creating/editing post if I upload a new image then it gets attached with the post and I get it, but if I use an already uploaded image in the post I don't get that media. Am I missing something here?
Upvotes: 1
Views: 78
Reputation: 154
you can try with this function.
$attch_id = get_post_thumbnail_id( $post->ID );
$url = wp_get_attachment_image_src($attch_id);
echo "<img src='".$url[0]."' />";
I hope is useful.
Upvotes: 1