Delaying the Feed Publishing Time

Written by Bec on April 13, 2009 – 8:30 AM -

I’m pretty sure we’ve all done it… or will. We hit publish and then see some silly typo or error. But, alas, the feed has flashed out over the internet and into your reader’s view, with the errors front and center. If you’d like to be able to delay your feed from publishing by a few minutes so that minor errors could be caught and fixed, you’ll find the following code hack from WP Engineering a real blessing. If you put the following syntax in the functions.php of your theme, then your feed will be published always 5 minutes later. Of course you can adjust the time, and the units, if you need to.

Note: if your theme doesn’t have a functions.php, then create one.

/**
* puplish the content in the feed later
* $where ist default-var in WordPress (wp-includes/query.php)
* This function an a SQL-syntax
*/
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');

Thanks to WP Engineering for this sweet little hack to delay the feed publishing time!


Tags: ,
Posted in Articles & Tutorials, Wordpress | 1 Comment »
RSS