get_rss() WordPress Function

The get_rss() function allows you to display RSS feeds on your WordPress site. You can use this function to display an RSS feed from any site that has an RSS feed.

get_rss( string $url, int $num_items = 5 ) #

Display RSS items in HTML list items.


Description

You have to specify which HTML list you want, either ordered or unordered before using the function. You also have to specify how many items you wish to display. You can’t display all of them like you can with wp_rss() function.


Top ↑

Parameters

$url

(string)(Required)URL of feed to display. Will not auto sense feed URL.

$num_items

(int)(Optional) Number of items to display, default is all.

Default value: 5


Top ↑

Return

(bool) False on failure.


Top ↑

Source

File: wp-includes/rss.php

function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS
	$rss = fetch_rss($url);
	if ( $rss ) {
		$rss->items = array_slice($rss->items, 0, $num_items);
		foreach ( (array) $rss->items as $item ) {
			echo "<li>\n";
			echo "<a href='$item[link]' title='$item[description]'>";
			echo esc_html($item['title']);
			echo "</a><br />\n";
			echo "</li>\n";
		}
	} else {
		return false;
	}
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.