Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

stylishjm on "Fetch Feed - unable to change feed cache time from default 12 hours"

$
0
0

So I'm using WordPress's fetch feed function to display an RSS feed of latest posts from our vBulletin forum on our home page (see function reference here)

Here is what I've currently implemented (minus unrequired divs etc.)

<?php
include_once( ABSPATH . WPINC . '/feed.php' );
//Url for forum rss feed
$rss = fetch_feed( 'http://www.grimeforum.com/forum/external.php?type=RSS2&forumids=2&lastpost=1' );
if ( ! is_wp_error( $rss ) ) :
// quantity of posts to display
$maxitems = $rss->get_item_quantity( 4 );
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>

<?php if ( $maxitems == 0 ) : ?>
<?php _e( 'No items', 'grimeforum' ); ?>
<?php else : ?>
<?php foreach ( $rss_items as $item ) : ?>
<div class="forum-post">

<img src="<?php bloginfo('template_directory'); ?>/img/unknown.gif" alt="<?php echo esc_html( $item->get_title() ); ?>" width="35" height="35" />

<a href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank" title="View thread on the forum">
<?php echo esc_html( $item->get_title() ); ?>
</a>

Posted by
<?php if ($author = $item->get_author()){
echo $author->get_name();} ?>
<?php printf( __( 'on %s', 'grimeforum' ), $item->get_date('g:i a') ); ?>

Now that display fine, however it is caching every 12 hours. I need this to be more often (every 30 minutes to be exact).

I've tried adding the following to functions.php as described here.

function return_7200( $seconds )
{
  return 1800;
}

add_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );
$feed = fetch_feed( $feed_url );
remove_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' );

It's still caching every 12 hours. Is there something I'm misunderstanding?


Viewing all articles
Browse latest Browse all 8245

Trending Articles