Friday, September 10, 2010

TutZone- Tutorials, Design news and Inspiration

TutZone- Tutorials, Design news and Inspiration

Link to TutZone

Control When Your Posts are Available Via RSS

Posted: 10 Sep 2010 03:45 AM PDT


There are times when after making a post live we realize it needs something to be changed or modified correctly. You go back to admin panel and change it but the post is already published in your RSS feeds. But with this simple trick you can delay the time after which the post becomes live on RSS feeds also so that you get sufficient time to double check your post.

Procedure:

Note: Do take backup of your theme before you try this.

01. In your WordPress Admin panel go to Appearance => Editor.
editor

02. Then choose functions.php file from right hand side and add below code:
functions.php

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');


03. In above code change 5 to the time delay you want in your RSS feed publication. In above example it is set to 5 Minutes.

That concludes this simple and useful tutorial. Hope you like it.

No comments:

Post a Comment