Retriving Post Data from WordPress Database

I am learning plugin development recently. I am trying to develope a test plugin which will show a table of lists of Drafts post. To achieve this I am running below query in my plugin. But I can see the Table is empty.

<table class="widefat">
            <th>Post Title</th>
            <th>Post ID</th>
            <th>Post Title</th>
            <th>Post ID</th>
        <?php global $wpdb; $mytestdrafts=$wpdb->get_results( "SELECT ID, post_title FROM $wpdb->wp_posts WHERE post_status = 'drafts' " ); 
        foreach ($mytestdrfts as $mytestdraft){ 
            echo "<tr><td>".$mytestdraft->post_title."</td><td>".$mytestdraft->ID."</td></tr>";

Any Idea why it is not working ? Also another thing is that in that tutorial from where I learned it I have seen that FROM $wpdb->wp_posts in this query he used FROM $wpdb->posts. But I have seen that the table is “wp_posts” . However I tried both “posts” and “wp_posts” table in the query. But same result. Any idea ?

Thanks in advance

Source: wpdb

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.