Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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