DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Did you ever published an article, and immediately notice an error? Sure, you can edit it, but there’s another problem: The article has already been published on your rss feed. To avoid that kind of problem, here’s a recipe to create a delay between post publication and availability throught rss feeds.

To achieve this recipe, simply 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() ) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');
 
		// value for wait; + device
		$wait = '5'; // integer
 
		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
 
		// add SQL-sytax to default $where
		$where.=" AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}
 
add_filter('posts_where', 'publish_later_on_feed');

The above code will add a 5 minutes delay between your post being published on your blog, and on your rss feed. To change the delay, change the value of the $wait variable, on line 9.

Credits goes to WpEngineer for this awesome recipe!

Tags

Leave a Comment

Your email address will not be published. Required fields are marked *