How to Display and Sort Two RSS Feeds Together in WordPress
If you’re looking to combine multiple RSS feeds on your WordPress site and display them sorted by publish date, the method is straightforward using PHP and WordPress’s built-in fetch_feed() function.
Whether you’re aggregating content from two different blogs or sources, this guide will help you merge, sort, and display RSS items cleanly.
âś… PHP Code to Fetch, Combine, and Sort Two RSS Feeds
<?php
include_once( ABSPATH . WPINC . '/feed.php' );
// Fetch the first RSS feed
$rss1 = fetch_feed( 'https://example.com/feed1/' ); // Replace with your first feed URL
$rss_items1 = ! is_wp_error( $rss1 ) ? $rss1->get_items( 0, $rss1->get_item_quantity( 5 ) ) : [];
// Fetch the second RSS feed
$rss2 = fetch_feed( 'https://example.com/feed2/' ); // Replace with your second feed URL
$rss_items2 = ! is_wp_error( $rss2 ) ? $rss2->get_items( 0, $rss2->get_item_quantity( 5 ) ) : [];
// Merge both feeds
$combined_items = array_merge( $rss_items1, $rss_items2 );
// Sort combined items by date (newest first)
usort( $combined_items, function( $a, $b ) {
return $b->get_date( 'U' ) - $a->get_date( 'U' );
});
?>
<div class="rss-feed-container">
<?php if ( ! empty( $combined_items ) ) : ?>
<?php foreach ( $combined_items as $item ) : ?>
<div class="rss-item">
<a href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank">
<?php echo esc_html( $item->get_title() ); ?>
</a>
<small><?php echo esc_html( $item->get_date( 'F j, Y' ) ); ?></small>
</div>
<?php endforeach; ?>
<?php else : ?>
<p>No feed items available at the moment.</p>
<?php endif; ?>
</div>
🎨 Optional CSS for Styling
.rss-feed-container {
padding: 15px;
background-color: #f9f9f9;
border: 1px solid #ccc;
max-width: 600px;
}
.rss-item {
margin-bottom: 12px;
padding-bottom: 10px;
border-bottom: 1px solid #ddd;
}
.rss-item a {
font-weight: bold;
text-decoration: none;
color: #2c3e50;
}
.rss-item small {
display: block;
color: #777;
margin-top: 4px;
}
🛠️ Customization Options
You can easily enhance or modify this setup based on your needs:
- Change item limits per feed (e.g., display 3 or 10 items).
- Add feed titles above each section, if you prefer separating sources.
- Display excerpts or authors if supported by the feeds.
- Paginate the feed list for better UX.
By combining and sorting multiple RSS feeds, you can create automated content hubs, partner news sections, or even cross-blog features that stay fresh with minimal effort.








