0

I'm using the following code to display some entries of my WordPress blog as a feed in the sidebar. The problem is, it's not updating no matter what I do. It still only shows the first "Hello World" post, even though I've added others, and it doesn't even show the updated name of that post after I've changed it. Thought this might be a caching issue, but if I actually click into the feed XML, the data is updated- which makes no sense to me??

    <?php
    // Blog Feed:
    $rss_url = get_option('home')."/feed/";
    ?>

    <ul class="side-feed">

    <?php if(function_exists('fetch_feed')) {

        include_once(ABSPATH . WPINC . '/feed.php');               // include the required file

        $feed = fetch_feed($rss_url); // specify the source feed

        $limit = $feed->get_item_quantity(3); // specify number of items
        $items = $feed->get_items(0, $limit); // create an array of items
echo count($items);
    }
    if ($limit == 0) echo '<div>(None)</div>';
    else foreach ($items as $item) : ?>

        <li><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></li>

    <?php endforeach; ?>

    </ul>
Yarin
  • 173,523
  • 149
  • 402
  • 512

1 Answers1

3

Wordpress caches feeds for 12 hours by default, to change this you need to hook into the wp_feed_cache_transient_lifetime filter and return the number of seconds you want to cache for.

add_filter('wp_feed_cache_transient_lifetime', create_function('', 'return 60*60;'));
Richard M
  • 14,244
  • 6
  • 52
  • 48