Blog Madness

e-Marketing tips

Thursday, February 11, 2010

control when your wordpress posts are displayed in your rss feed

The problem: Have you ever published an article and then immediately noticed an error? Sure, you can edit it, but there’s another problem: the article has already been published in your RSS feed. To avoid this kind of problem, use this recipe to create a delay between the publication of a post and its availability in your RSS feed. The solution: Paste the following code into your theme’s function.php file. (If your theme doesn’t have this file, just create it.)
function publish_later_on_feed($where) { global $wpdb; if ( is_feed() ) { $now = gmdate('Y-m-d H:i:s'); $wait = '5'; $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; } return $where; } add_filter('posts_where', 'publish_later_on_feed');
Your RSS feed will now be updated 5 minutes after you have published your new blog post.