Back to Top

How to fetch and display feed in WordPress

How to fetch and display feed in WordPress

Feeds are very useful features to read contents.So, Today I am going to explain about how to use the feed in WordPress and which functions WordPress provides for feeds.

As you all know WordPress provides the feature for reading feeds and using it in your blog.Wordpress has function fetch_feed() to work with feeds in WordPress and you can cache feed data using this function.

The fetch_feed() function checks the feed in every 12hours so data will be automatically deleted after 12 hours.fetch_feed() function cache data into transients by WordPress transients API.so you can get cached data transients into table wp_options.

SYNTAX

fetch_feed() function call with the URL of the feed and returns a feed object that we store in the $feed.

Basically, fetch_feed() uses SimplePie library of core WordPress is a simple way for fetching a feed. SimplePie is stable user-friendly class and documentation and ease of use is awesome, even if the functionality to retrieve the feed looks more complicated on this end.

Above small example reads the feed and if no error enables the cache and set its duration.Then You can use functions like get_items(), get_permalink(), get_title() to grab data from the feed and display on the screen.WordPress caches feed data using transient api into database and clear every 12 hours so

To clear cache forcefully,use filter into functions.php or plugin file

And if you don’t want to cache feed, set false in enable_cache

Conclusion

The fetch_feed() function is the simplest way to customize or update your WordPress blog.Nowadays every site has feeds so you can easily scrape content and publish in your website.

Suggested Reading:

Parsing an RSS Feed with WordPress
Add items to top navigation in WordPress
To Create own directory in WordPress Upload folder

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use session in Magento

Posted on 11 years ago

Bhumi