Skip to content

Instantly share code, notes, and snippets.

@napsternxg
Created June 16, 2010 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save napsternxg/440779 to your computer and use it in GitHub Desktop.
Save napsternxg/440779 to your computer and use it in GitHub Desktop.
function returnFirstPostImage($id){
global $wpdb;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$pattern = '!<img.*?src="(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0];
return $image_src;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment