Blog

WordPress & MySQL – Query Database

Posted On:

Here $wpdb->get_results will fetch associative array of values ... multiple values

either you need to loop through each of them using

$sql = "SELECT * FROM wp_posts WHERE post_type='video'";
$results = $wpdb->get_results($sql) or die(mysql_error());    
if (count($results) > 0) {
    $display_row = null;
    foreach ($results as $res) {
         echo "id - " . $res->id;
    }
} 
or if you're expecting only one row, then try this

$result = $wpdb->get_row($sql);
echo "id - "$result->id;

Comments