• Resolved tomleads

    (@tomleads)


    I had the following code working fine with 2.8

    <ul>
    <?php
    if(function_exists('fetch_feed')){
    	$uri = 'https://search.twitter.com/search?q=test';
    	$feed = fetch_feed($uri);
    	$maxitems = $feed->get_item_quantity(2);
    }
    ?>
    <?php
    //printf( $feed->get_title());
    foreach ($feed->get_items(0, $maxitems) as $item){
    $links = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link');
    $img = $links[1]['attribs']['']['href'];
    echo "<li>";
    printf('<a href="%s"><img alt="%s" src="'.$img.'" /></a>',$item->get_permalink(), $item->get_title());
    //printf('<h2><a href="%s">%s</a></h2>',$item->get_permalink(), $item->get_title());
    echo "<p>";
    printf('%s',$item->get_description());
    //printf('%s',$item->get_link());
    printf(' <strong>%s</strong>',$item->get_date('j F Y | g:i a'));
    echo "</p>";
    echo "</li>\n";
    }
    ?>
    </ul>

    I upgraded to 2.9 and I get the following error:

    Fatal error: Call to undefined method WP_Error::get_item_quantity() in domain\wp-content\themes\mytheme\footer.php on line 14

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Going by the codex your code is correct. Only thing is, is the uri specified valid? I would suggest that you should be referencing
    twitter.com/search.atom?q=test rather than twitter.com/search?.

    It could be that an invalid resource is returning an error when you come to run operations on the feed.

    Thread Starter tomleads

    (@tomleads)

    Fantastic, that was the exact fix ??

    Thanks

    I’m getting the same problem with a finicky rss feed. Is there a way I can skip the code if it returns an error?

    Figured it out.

    If the feed you’re referencing is empty, simply check if the number of items equals zero:

    if ($rss->get_item_quanity != 0) { run the code } else { run something else }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_item_quantity WordPress 2.9 error’ is closed to new replies.