Publish your WordPress site’s Feed Later

If you have ever faced the problem of publishing a post with an error that you haven't noticed but this post is already included in a feed that is published to the whole world, then you will probably find this article very useful!

Using the following code you can have your new posts published to your feed 15 minutes later. Of course you can adjust the time and unit at will. Edit your theme's functions.php file and add the following code:

/**
* publish 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 = '15'; // 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');

Explanation: WordPress works with a special query, which acts differently depending on the user rights. This query is saved in the variable $where and is differently assembled, therefore you may extend it. There is a mySQL function timestampdiff(). You 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 blog.

Source: http://wpengineer.com/publish-the-feed-later/

Tags: ,

Author: Galadriel

Leave a Comment