Publish The Feed Later

Some of you know this problem already, you publish a post and while you are publishing you notice an error. That's very annoying, the error is in your feed an published to the whole world.

That happened quite often to me, my fellow readers a writing comments so fast, right after publishing, to tell me about some errors I made, it's unbelievable. So I thought I should create a workaround to have the feed published a little bit later, even 5 minutes can be helpful. Here we go:

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(). I 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.

The following example publishs the post 5 minutes later in your feed:

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

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, if you need it in a special case. I probably will add this feature in the next release of my plugin ©Feed.

21 Comments and 11 Trackbacks/Pingbacks

  1. [...] number of edits that need to be made?  For these people, WP Engineer has written a post explaining how to publish a feed later using your functions.php file.    This way you can publish posts on your blog, then have time to [...]

  2. [...] WPengineer gibt es einen tollen Tipp samt Code zum Thema Publish The Feed Later - für alle, die wie ich manchmal auf “Publizieren” klicken, bevor die letzten Fehler [...]

  3. 3. garaj kapısı

    November 10th, 2008 at 11:19 pm

    Thanks for this tip.

    But i dont understand, why u want that publish later?

  4. 4. Alex

    November 11th, 2008 at 12:00 am

    Hey Garaj,

    the reason why you might want to publish later is pretty simple. When you publish your feed, people will get your post with all errors immediately. It takes time before the feed updates, if you update your post, it will show the changes immediately, but your feed will stay the same until the next update, an update period can take hours, which is annoying, if all your readers can read the errors in your feed, even if you had correct it some hours ago. Hope that makes it clear. :)

  5. 5. Ozh

    November 12th, 2008 at 8:15 am

    Ola there
    Off topic: could anyone from this site contact me? (I couldn't find any "Contact" form or link here). I'd like to add your site to http://planetwordpress.planetozh.com/
    Thanks in advance

  6. 6. Alex

    November 12th, 2008 at 2:33 pm

    Hey Ozh,

    I just sent you an email, glad to be part of your planetozh :)

    Thanks a lot, can't be a better compliment!

  7. 7. Christian Ross

    November 26th, 2008 at 3:31 am

    Thanks for the tip/code. Always find myself finding mistakes minutes after I publish an article.

    Any way to edit a feed once it is already published?

  8. 8. Alex

    December 1st, 2008 at 12:22 am

    You are welcome Christian

  9. [...] Publish your feed later [...]

  10. 10. Simon

    December 3rd, 2008 at 3:47 pm

    Hey there Alex sounds like the right hack for me! Though when pasting it like this into my function.php I get errors in my wp-admin and a white stripe on top of my blog design. What could cause that?

  11. 11. Alex

    December 5th, 2008 at 11:28 am

    Hey Simon, can you tell me what exactly does it say in your error.

    Thanks

  12. [...] originale artikel omkring dette ene tip, kan findes på wpengineer.com. Nu vil jeg ikke tage nogen form for credit, men det virker ganske simpelt, og det eneste der skal [...]

  13. [...] Автор данной методики предлагает вставлять определённый блок кода в файл functions.php текущей темы. Но, во-первых, это не дружественно по отношению к пользователю (в случае ошибки WordPress выплюнет fatal error), во-вторых, может быть автоматизировано, в-третьих, при смене темы файл придётся заново редактировать и в четвёртых — всё можно сделать проще [...]

  14. 14. Publish The Feed Later

    December 9th, 2008 at 1:01 pm

    [...] Publish The Feed Later - WP Engineer. DJ Email Publish Wordpress PluginWhen you publish a new post, this plugins will send the post to your other blogs (such as msn spaces) via email. ...LinkAssure - Free RSS Feed WriterLinkAssure has made Really Simple Syndication (RSS) even simpler with our free RSS Feed Writer. Once you’ve completed this step, you’ll be able to add specific items to your RSS feed and generate the free “copy & paste” XML code required to publish your own feed for syndication. Free RSS Feed Writer - XML RSS Feed Builder - RSS Editors ...Feed FrenzyOver the last six months, it seems like every web site is adopting the notion of a "News Feed". These feeds keep me informed about the status/actions of all my friends and relationships. I have a Facebook News Feed. I have a Twitter Feed. I have a LinkedIn Feed. And even more recently, a new category of products called Feed Aggregators have arrived. These aggregators, such as FriendFeed and SocialThing, allow you to track your feeds across multiple sites. There has even been a spoof site that aggregates the aggregators. Feed Frenzy... [...]

  15. 15. Simon

    December 10th, 2008 at 10:55 pm

    Actually, pasting exactly the same as above into the functions.php I get this on top when I want to log in to the admin back.

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

  16. 16. Michael

    December 11th, 2008 at 9:53 am

    Simon, you have to use php tags before and after the code like that:

    <?php
    //here comes the code
    ?>

  17. 17. Simon

    December 11th, 2008 at 10:40 am

    Grand Michael I tried that yesterday, good to have the confirmation. Thanks a lot!

  18. 18. RupertGee

    December 11th, 2008 at 12:21 pm

    Marvelous hack!

    I can't count how many times I accidentally broadcast unfinished post.

    Thanks!

  19. [...] Publish your feed later [...]

  20. 20. Alex

    December 13th, 2008 at 10:12 pm

    You are welcome Rupert :)

  21. [...] like me, you tend to catch at least one typo after you hit publish, here’s a handy bit of php magic that will delay posting new entries to your RSS feed for 5 minutes. You can put it in your [...]

  22. [...] Эта фора может оказаться полезной для вас, и не только в смысле определения первоисточника, но и просто для проверки поста. Нередко бывает, что опубликовав материал, находишь в нем несколько досадных ошибок, но в RSS он уже ушел, а значит и читатели эти ошибки увидели. Задержка отправки в RSS решает эту проблему. Техника подсмотрена здесь. [...]

  23. 23. yemoonyah

    December 17th, 2008 at 7:09 pm

    Okay, I tried to add the code at the end of my functions php and this is what I get when I want to go to my admin:

    Fatal error: Call to undefined function add_filter() in /.../.../public_html/wp-includes/functions.php on line 2928

    can you help?

    Thanks for posting, is exactly what I need!

  24. 24. Michael

    December 17th, 2008 at 8:13 pm

    yemoonyah, you have to use the functions.php in your theme folder, not the wp-includes/functions.php.
    If you don't have a functions.php in your theme folder, create one.

  25. 25. Sjakelien

    December 18th, 2008 at 1:46 am

    OK, I think this mechanism is very close to something I'm looking for. The problem is that I don't know PHP.
    What I would like to see is the following:
    An algorithm, that, given a specific category, would delay the publishing of a post.
    So, for instance: if the category is "Sports", the delay would be one day. If the category is "Hot News", the delay would be zero.
    Is there anyone around here who could write up something for me? Thanks in advance.
    I'll send you something from the Netherlands...

  26. 26. Frank

    December 18th, 2008 at 12:08 pm

    Sjakelien: Yes this is also possible. PLease check this with the conditional tags:
    if ( is_feed() && is_category('6') ) {

  27. 27. Sjakelien

    December 18th, 2008 at 2:18 pm

    OK,thanks, but where would I put that, and what would the publication date/time parameter be?

  28. 28. salzano

    December 19th, 2008 at 5:49 pm

    awesome! this is exactly what i need. small typo in your function name, btw...

    pulish => publish

  29. 29. Michael

    December 19th, 2008 at 6:21 pm

    Thanks salzano! Fixed.

  30. 30. Michael

    December 20th, 2008 at 3:42 pm

    Sjakelien, in the same function.

    function publish_later_on_feed($where) {
    ...
    if ( is_feed() && is_category('6') ) {
    ...

  31. [...] published them, this little trick could save you some embarrassment. Frank from wpengineer has posted some code that will allow you to specify a delay between the publishing of your posts and their delivery to [...]

  32. [...] goes to WpEngineer for this awesome recipe! Did this tip help you? If so, feel free to make a small [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">