WP RSS solution

Tags:

Unmemorable Memories » Blog Archive » Bugs and Free Software has a solution to the WordPress RSS privacy problem I talked about: 

Bugs and Free Software

Here’s a bug I noticed with wordpress. If you write a post in wordpress, but save it as a draft without posting it, these articles will still show up in your “Recent Posts” item in the sidebar (using the Kubrick Theme). I’m not sure if this is a bug in the Theme or in Wordpress itself. The Kubrick sidebar calls wp_get_recent_posts() to get the list of recent posts. However wp_get_recent_posts() queries the database for all posts including published, drafts, and private posts. When you then click on the link to a draft article, you get a 404 not found error message. Quite annoying, and definitely a bug.

The solution is to create a new function in functions-post.php called wp_get_recent_published_posts(). This function is a copy of wp_get_recent_posts() with one thing changed: the MySQL query for the post should not include posts whose status is draft. This is accomplished by changing the following line:

$sql = \"SELECT * FROM $wpdb->posts \
WHERE post_status \
IN (’publish’, ‘draft’, ‘private’) \
ORDER BY post_date DESC $limit\";

to

$sql = \"SELECT * FROM $wpdb->posts \
WHERE post_status \
IN (’publish’, ‘private’) \
ORDER BY post_date DESC $limit\";

Then we can change the sidebar.php from the Kubrick theme to call wp_get_recent_published_posts() instead of the buggy wp_get_recent_published_posts().

Why create a new function instead of fixing the buggy one? There may be other functions that call wp_get_recent_posts() which depend on that buggy functionality. By creating my own function, and calling that, I can localize the fix to the place where it is manifested. I am able to fix the bug without introducing new ones.

Leave a Reply

If the above Image does not contain text, use this secure code: VUDsFshV