The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] get_item_quantity WordPress 2.9 error (5 posts)

  1. tomleads
    Posted 6 years ago #

    I had the following code working fine with 2.8

    	$uri = 'http://search.twitter.com/search?q=test';
    	$feed = fetch_feed($uri);
    	$maxitems = $feed->get_item_quantity(2);
    //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(' <strong>%s</strong>',$item->get_date('j F Y | g:i a'));
    echo "</p>";
    echo "</li>\n";

    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
    Posted 6 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
    Posted 6 years ago #

    Fantastic, that was the exact fix :)


  4. freshifreshy
    Posted 6 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
    Posted 6 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