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.


Posted

in

by

Comments

65 responses to “Publish The Feed Later”

  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. garaj kapısı Avatar

    Thanks for this tip.

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

  4. Alex Avatar

    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. Ozh Avatar

    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. Alex Avatar

    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. Christian Ross Avatar

    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. Alex Avatar

    You are welcome Christian

  9. Simon Avatar

    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?

  10. Alex Avatar

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

    Thanks

  11. […] 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 […]

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

  13. […] 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… […]

  14. Simon Avatar

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

  15. Michael Avatar

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

    <?php
    //here comes the code
    ?>

  16. Simon Avatar

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

  17. RupertGee Avatar

    Marvelous hack!

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

    Thanks!

  18. Alex Avatar

    You are welcome Rupert 🙂

  19. […] 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 […]

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

  21. yemoonyah Avatar

    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!

  22. Michael Avatar

    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.

  23. Sjakelien Avatar
    Sjakelien

    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…

  24. Frank Avatar

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

  25. Sjakelien Avatar
    Sjakelien

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

  26. salzano Avatar

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

    pulish => publish

  27. Michael Avatar

    Thanks salzano! Fixed.

  28. Michael Avatar

    Sjakelien, in the same function.

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

  29. […] 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 […]

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

  31. […] Publish The Feed Later – WP Engineer Categories: Programming, Web Stuff. Tags: RSS, wordpress. […]

  32. Simon Avatar
    Simon

    Is it possible I’ve got some settings wrong here? I don’t get any feedburner mails/feed anymore since adding this (exact copy) to my functions.php?
    Thank you a lot!

  33. Erik Avatar

    I found that when I pasted this into the functions.php file it would cause my RSS feed to no long work. If you went to the URL of the feed there would be a page not found error and feedburner could no longer use the feed.

    I found that once this was code was deleted from the functions.php file everything worked again. I liked the concept of this but if using it is going to cause my feed to be unavailable I will deal with publishing the RSS at the same time.

    Have you encountered any one else with this problem?

  34. Simon Avatar
    Simon

    Yeah Erik, same thing here although the feedburner feed is still there, just with all the items up to when I added the code to the functions.php. Any recommendations?

  35. Frank Avatar

    The code works fine and i think you have only a problem in your theme or a problem with other plugins. The function wait 10 minutes and the is the same content in the feed. Feedburner scan the code in different interval with and publish later. Maybe is this a problem with this function.

  36. Erik Avatar

    I tried it with the default WordPress theme and it was still causing the same problem. I turned off all of my plug ins and there was still the same problem. It had nothing to do with Feedburner this code caused the feed from WordPress (url.com/feed) to no longer work.

  37. Frank Avatar

    I have tested the code under many blogs and i use the code in many live blogs. Do you have correct copy the code in the functions.php of the Theme, with the php-tags?

  38. […] En el ejemplo lo retrasa 5 MINUTE, pero podemos hacer que espere lo que nosotros queramos […]

  39. ookla Avatar
    ookla

    Hey dude.. can you help me?

    My server time (php date): 9:13 AM
    My server time (php gmdate): 5:13 PN
    Wordpress time: 1:13 PM

    How can I change your var _now to make this works with this?

    thanks

  40. ookla Avatar
    ookla

    fixed.. it was that ‘greater than’ character

  41. AlexPTS Avatar

    Why Publish The Feed Later?

  42. Azzam Avatar

    @AlexPTS. Answered in a previous comment.

    Do I still need to apply this if I am using feedburner since you mention that is scans in intervals?

  43. […] Publish the Feed Later hos WP Engineer […]

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

  45. […] ik heb het stukje script uitgezet waarmee je publicatie van een bericht naar je RSS feed kan uitstellen. Dit lijkt niets te veranderen en is waarschijnlijk niet de oorzaak van het […]

  46. Erik Avatar

    It just came to my attention that my feed seems to have a delay of 1 message.

    So if I post a message, the message before that one appears in my feed. My readers read my blogposts when they are already dated.

    I neutralized this script and my issue was over. I am going to switch it on later this day just before publishing a new artciel to double check if it really originates from this script.

  47. Ves Avatar

    Hey Erik, I’m having the same problem. On the site we work (WP 2.7.1) we’re getting same kind of delay.

  48. erik Avatar

    I still have this issue and not sure what is the reason. If i post a message it is not included in the fed directly, even after pinging and a refresh (I use feedburner).

    last time it worked when I changed the time of posting. I do not spend much time testing since it is a smaller blog where this happens.

  49. Sean Turtle Avatar

    Thanks very much – really appreciated!

  50. Carlos Reveco Avatar

    I create this script to publish rss weekly based on this post.
    Thanks for the idea!
    add this script in your functions.php of your theme.

    /**
    * 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_weekly_on_feed($where) {
    global $wpdb;

    if ( is_feed() ) {
    $day=date(N);

    $now = gmdate(‘Y-m-d H:i:s’);

    // value for wait; + device
    $wait = ‘1’; // integer
    // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
    $device = ‘WEEK’; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

    $where .= ” AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, ‘$now’) > $wait “;

    $where .= ” OR $day = ‘4’ “; //1 = monday, 2= tuesday …. 7 =sunday
    }
    return $where;
    }

    add_filter(‘posts_where’, ‘publish_weekly_on_feed’);

  51. […] 前面已经介绍了可以通过ping来使搜索引擎或者feed第一时间更新,也提供了一些常用的Ping地址列表。但是前几天在网络上也看到了这样的帖子“如何延迟Feed更新”,目的是可以在延迟的时间里再检查下文章有没有问题。我要说,为什么非要等到发布之后才想到检查呢? […]

  52. Andy - The Digitante Avatar

    I just tossed this in my function.php but I haven’t published since doing so. We’ll see how it goes tomorrow!

    Thanks!

  53. […] Publish The Feed Later: WP Engineer provides a nice tutorial on how to publish your post to your feed a few minutes (configurable) after you publish your post. These few minutes can help you find errors or bugs in your post and fix them before they get sent out via your feed to all your readers. The “hack” requires you to change your theme’s functions.php file and add the code snippet provided. Alternatively you could also use a plugin written by our very own Keith, called Feed Pauser. I see no compatibility information on this plugin (maybe Keith could chime in and let us know) but it does offer further functionality such as the ability to prevent individual posts from appearing in your feed. A useful hack/plugin for those like me who have an itchy post finger. (No Ratings Yet)  Loading …   Tags: feed pauser, rss feed Visited 1 times […]

  54. Matt Avatar
    Matt

    How can I delay just one feed. I’d like my main feed to publish immediately, but I’d like to have another feed that I can provide to my syndication partners that has a delay. Any suggestions?

  55. […] your RSS feed readers. With your credibility forever tarnished, all hope is lost. Right?Luckily, WPEngineer has a solution for you. Simply add this code to your functions.php file: /** * puplish the content […]

  56. Joe Avatar
    Joe

    I would also like to know how to delay just one feed, while leaving other feeds not delayed. Or how to create a special xml page that displays the delayed version of the feed.

  57. MIDD Avatar
    MIDD

    Our website uses wordpress as a platform. We tested our RSS and there’s a whole month delays. So the blog post i’ll get on my outlook or google reader would be the post last month rather than the latest one. Where could the problem lie?

    Is it the same principle as this? I mean delaying 5 minutes. Could it be possible that rather than delaying 5 minutes, ours is delayed in 30 days?

  58. Ice Avatar

    I’ve tried your function…works great!

    Now…how can I add to the function a filter that excludes posts that have already been published? Sometimes I update a post and I don’t want these updated posts going back through the feed.

    I’m thinking I could use a custom field to mark the post but I just don’t know how to write the query.

    Thanks

  59. Edi at web Avatar

    Thanks for this guide. But if i want that google index content fast i ping rss feed. One real scenarion:
    – aggregator post in blog
    – blog generate feed from posts
    – i ping by cron job generated rss feed

    Is simple – if feed is generated after 5 minutes, just content will be indexed after 5 minutes. In this way you must create 2 feeds – one public that is with 5 or better with 15 minutes delay and one private that you will use only to ping google to index .