I need to get the first image of the post in wordpress.
I have various posts. So for new posts, I can set the featured image. However there are thousands of old posts. I need to extract the first image from those posts so that I can use them to display.
I used the code from http://css-tricks.com/snippets/wordpress/get-the-first-image-from-a-post/ and I dont think its working for me.
global $post;
$args = array( 'posts_per_page' => 10, 'category' => 6 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
......
.....
endforeach;
I need to display the image from each post lets say as in a gallery in the form of thumbnails. I searched a lot but could not figure out how.
Put this in your
functions.php
Then use in your template
getTheFirstImage()
function where you want to print the imageCheck this forum post.