Get row
Get row sử dụng trong trường hợp bạn muốn lấy ra 1 record.
Ví dụ như:
Get bài viết theo ID
Get user theo mail
Get chuyên mục theo ID
Để lấy dữ liệu thoe kểu row chúng ta sử dụng đoạn code sau:
<?php
global $wpdb;
$postID = 5; // id bài viết cần lấy
$table = $wpdb->prefix . 'posts'; // Bảng cần lấy
$sql = "SELECT * FROM {$table} WHERE `ID` = %d"; //câu sql query
$data = $wpdb->get_row( $wpdb->prepare($sql, $postID), ARRAY_A); //trả về dữ liệu trong biến $data
?>
Last updated