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` asdate, `post`.`post_title` as title, `post`.`post_name` as slug, `thumb_link`.`meta_value` asimageFROM $table as postLEFT 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` DESCLIMIT %d OFFSET %d";return $data = $wpdb->get_results( $wpdb->prepare($sql, $limit, $offset), ARRAY_A);?>