I am new in WordPress I want to get all records from wp_posts table which are drafted, but no record found. My query is the follow:
<?php
global $wpdb;
$resultsOb = $wpdb->get_results(
"SELECT ID,post_title
FROM $wpdb->wp_posts
WHERE post_status = 'draft'
"
);
// loop the objects
foreach($resultsOb AS $result) {
?>
<tr>
<td><?php echo $result->ID;?></td>
<td><?php echo $result->post_title;?></td>
</tr>
<?php } ?>
There’s a built-in function for this called get_posts(). In your case, usage would look something like: