WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_item_quantity WordPress 2.9 error (5 posts)

  1. tomleads
    Member
    Posted 4 years ago #

    I had the following code working fine with 2.8

    <ul>
    <?php
    if(function_exists('fetch_feed')){
    	$uri = 'http://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?

  2. Ben Sutcliffe
    Member
    Posted 4 years ago #

    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.

  3. tomleads
    Member
    Posted 4 years ago #

    Fantastic, that was the exact fix :)

    Thanks

  4. freshifreshy
    Member
    Posted 4 years ago #

    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?

  5. freshifreshy
    Member
    Posted 4 years ago #

    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 }

Topic Closed

This topic has been closed to new replies.

About this Topic