Publish the Feed of wordpress Later

December 30, 2008 · Print This Article

Did you ever published an article, and immediately notice an error? 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, we can create a delay between post publication and availability throught rss feeds.

WordPress works with a special query, which acts differently depending on the user rights. It is always saved in the variable $where and differently assembled. That means, you can extend it.

If you look at the possibilities of mySQL, there is a function timestampdiff(). We extend the query of WordPress with this function. Note to query the feed before (is_feed()), if not it will be also happening for the classical publishing of posts in your wordpress blog.

Simply paste the following code into your theme’s function.php file. If your theme doesn’t have this file, just create it.


/**
* puplish the content in the feed later
* $where ist default-var in WordPress (wp-includes/query.php)
* This function an a SQL-syntax
*/

function pulish_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', 'pulish_later_on_feed');

If you put the above syntax in your functions.php of your theme, then your feed will be published always 5 minutes later. Of course you can adjust the time, also the units.


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.