I’m trying to display multiple feeds using the fetch_feed function. Its working well thus far except I can’t figure out why the title for each individual rss feed will not show up.
Here is my code:
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
$rsslist = array( 'http://www.lt11.com/rss',
'http://feeds.feedburner.com/climbingnarc'
);
$rss = fetch_feed($rsslist);
if (!is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity(25);
$rss_items = $rss->get_items(0, $maxitems);
endif;
?>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
foreach ( $rss_items as $item ) : ?>
<li class="feed">
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_date('j/n/Y - g:i A') ); ?> - <div class="feeditemtitle"><?php echo esc_html( $item->get_title() ); ?></div> - <?php echo esc_html($rss->get_title() ); ?></a>
</li>
<?php endforeach; ?>
Its that list bit that calls for the title of the rss feed. If I only fetch one feed then the title shows up. When I fetch more than one feed as in the example above, the title does not show up. Any ideas on how to fix this? Thanks!
I don’t see anything to suggest that
fetch_feed
is supposed to accept an array of values. That is not mentioned in the Codex, nor the source,@param string $url URL to retrieve feed
.That said,
fetch_feed
passes things off to SimplePie’sset_feed_url($url);
which does accept an array. And that Simplepie docs page is, I think, where your answer is. The RSS feed name is$item->get_feed()->get_title()
not$rss->get_title()
I am still a bit cautious since you are passing an array through a WordPress function that doesn’t appear to be meant for it.
Display above code with featured image …