XML-RPC call to getRecentPosts does not return drafts in order
|Reported by:||cfinke||Owned by:|
When a blogging client makes a call to metaWeblog.getRecentPosts, drafts that were created in the Wordpress dashboard are not being returned interspersed among recent published posts. Instead, drafts are only included after all published posts, so if a client only requests the 10 most recent entries and there are more than 10 published posts in the history of the blog, no drafts will be returned.
The problem lies in this line in wp-includes/post.php in the function wp_get_recent_posts, which is used by xmlrpc.php to return a list of posts:
$sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC $limit";
Looking in my database, any time a draft is created via the Wordpress dashboard, it has a zeroed-out post_date and a post_type of 'post', but a new entry is immediately created after it that has an accurate post_date but a post_type of 'revision'. Either this behavior or the SQL should be changed; preferably the SQL in order to be backwards compatible with drafts already existing in this format.
(Bug reported on behalf of an estimated 450,000 Scribefire users, many of whom use Wordpress.)