I’m trying to get some of the latest posts from a Twitter account, without a plugin. According to Botcrawl.com’s tutorial, this should be enough:
<ul> <?php include_once(ABSPATH . WPINC . '/feed.php'); $rss = fetch_feed('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=BarackObama'); $maxitems = $rss->get_item_quantity(4); $rss_items = $rss->get_items(0, $maxitems); ?> <ul> <?php if ($maxitems == 0) echo '<li>No items.</li>'; else // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ) : ?> <li> <a href='<?php echo $item->get_permalink(); ?>'> <?php echo $item->get_title(); ?> </a> </li> <?php endforeach; ?> </ul>
However, I get the following error:
Fatal error: Call to undefined method WP_Error::get_item_quantity() in /Users/username/Desktop/journal_wp/wp-content/themes/Journal_theme/index.php on line 155
Has anyone had any experience with this, and know why it is calling a fatal error?
Read more here:: Pulling Twitter RSS feed not working as expected (fatal error)