A couple of days ago I wrote about how to use a RSS feed with the WordPress fetch feed function.
I was excited about figuring this out because I could place the feed wherever I wanted and didn’t have to worry about using a plugin.
I set it up in the evening and bookmarked a new page that should have updated the feed the following morning. Later in the day I noticed the feed hadn’t updated with the new bookmark so I started to worry that I hadn’t set it up properly or that it wasn’t going to be a workable solution.
So, I started to search and ask how often the fetch feed function pulls in the new feeds. I could not, however, find an answer to my question. That’s because I was asking the wrong question. The WordPress feed cache is what determines how often the feed is pulled in. In my search for answers I finally found this article by WP Engineer – Feed Cache in WordPress.
The article explains that by default the feed cache checks for updates to the feed every 12 hours. This is why me feed hadn’t updated. I had added the code almost 24 hours earlier but it hadn’t been 12 hours since I added the most recent bookmark to be pulled in.
The article also lists different ways to increase how often the field is pulled. I used the following code and added it to my functions file, functions.php:
<?php add_filter( 'wp_feed_cache_transient_lifetime', create_function( '$a', 'return 1800;' ) ); ?>
wp_feed_cache_transient_lifetime is a hook that works with the fetch feed function and can set how often the feed is checked for updates. The number 1800 refers to seconds, so in this example it is checking every 30 minutes. It probably doesn’t need to be this often – maybe something between 30 minutes and 12 hours ;-)
As WP Engineer mentions, this hook can be used in a function or in a plugin and can also be used with conditionals so that the feed is only checked and updated when specific pages are loaded.
So, mystery solved as to why my feed wasn’t being updated and I learned a little but more about WordPress that I intended when I first started playing with the fetch feed function.
photo credit: ~Sage~