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:

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);

<?php if ($maxitems == 0) echo '<li>No items.</li>';
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<a href='<?php echo $item->get_permalink(); ?>'>
<?php echo $item->get_title(); ?>
<?php endforeach; ?>

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?


That tutorial is no longer valid as Twitter's API have changed June 2013. There are are some great tutorials that came out just after June 2013 for Twitter API v1.1. Why not use a plugin. It is actually better to go that root as these plugin developers keep their plugins up to date and are quick to modify them if someone like twitter change their API

  • Thankyou, I may do that. Is there any you recommend (if I need to be able to customize the CSS) – tmyie Feb 26 '14 at 13:02
  • That is all personal choice. Go and try a few. Best of luck – Pieter Goosen Feb 26 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.