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!
8 Responses
I always double check my articles for typos and such. Anyway, overall it might be a useful trick. Cheers.
i just added this code to my site last week. i commented on the original author’s site that he’s got a typo in the code which you have duplicated here, but it will still run correctly despite pulish=>publish
@salzano: That’s right! Happilly the code still works, even with the typo
Hey Jean-Baptiste, thanks for publishing our recipe, even though there was a typo
Thanks for this recipe. Is there a way of making a particular post not available in RSS?
@Steve: Yes, you should put the posts you don’t want to be available via rss in a specific category and then exclude this category from the rss feed.
There’s other ways to do that though, I should write a recipe about it
Trackbacks: