I am fairly new and I am struggling with a simple Wordpress SQL query on the standard database for a plugin I am developing.
I am using the following code to echo out the titles of the first 10 posts:
global $wpdb;
$results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts LIMIT 0, 10;"));
$i = 0;
while($i < count($results)){
echo $results->post_title;
$i++;
}
But nothing is getting echo'd out to the screen. There are a more that 10 posts in the database so not having data is not the issue.
foreach ($results as $result) echo $result->post_title? Cus I believe the code you have now would always echo the same thing. Also, turn on error reporting.