WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/attachment icon

A little snippet of code for getting preview image of a post.

<?php
function prefix_get_image_thumb( $post_id ) {

	global $wpdb;
	
	$attachment_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_parent = '$post_id' AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1" );
	
	$thumb = get_attachment_icon( $attachment_id );
	
	echo $thumb;

}
?>
This page is marked as incomplete. You can help Codex by expanding it.