Truy vấn sql database wordpress get 10 bài viết mới nhất có hình đại diện

<?php 
        global $wpdb;
	$table 	= $wpdb->prefix . 'posts';
	$tablemeta 	= $wpdb->prefix . 'postmeta';
	$offset 	= 0;
	$limit 	        = 10;
	$sql = "SELECT  `post`.`ID`,
					`post`.`post_author` as author,
					`post`.`post_date` as date,
					`post`.`post_title` as title,
					`post`.`post_name` as slug,
					`thumb_link`.`meta_value` as image
	FROM $table as post
	LEFT JOIN $tablemeta as thumb_id ON `thumb_id`.`post_id` = `post`.`ID` AND `thumb_id`.`meta_key` = '_thumbnail_id'
	LEFT JOIN $tablemeta as thumb_link ON `thumb_link`.`post_id` = `thumb_id`.`meta_value` AND `thumb_link`.`meta_key` = '_wp_attached_file'
	WHERE 	`post`.`post_type` = 'post' AND `post`.`post_status` = 'publish' 
	GROUP BY `ID`
	ORDER BY `date` DESC
	LIMIT %d OFFSET %d";
	return $data = $wpdb->get_results( $wpdb->prepare($sql, $limit, $offset), ARRAY_A);
?>

Last updated