Support » Fixing WordPress » Fatal error: Call to undefined method WP_Error::get_item_quantity()

  • Resolved danazz09



    I’ve just published my website at and have since been getting the following error message:

    Fatal error: Call to undefined method WP_Error::get_item_quantity() in /home/danspor1/public_html/wp-content/themes/RSS Theme/home.php on line 21

    Where the error is changes depending on what page you are on, but pretty much in the get_item_quality() request.

    Here is a snippet of the code and where it is occurring:

    <?php include_once(ABSPATH. WPINC. '/feed.php');
    				$afl_link = fetch_feed('');
    				$maxitems = $afl_link->get_item_quantity(20);
    				$afl_items = $afl_link->get_items(0,$maxitems);
    			 	if ($rss->get_item_quanity = 0){
    					echo "There are no Feeds";
    				} else 	if( is_wp_error( $feed ) ) {
    					echo $rss->get_error_message(); // a method of WP_Error
    	  			} else {
    					$i = 0; 
    					foreach ($afl_items as $item) { ?>
    						<?php $i++;
    						if($i % 2 == 0) $odd_or_even = 'even';
    						else $odd_or_even = 'odd'; ?>
    						<div class="post<?php echo $odd_or_even; ?>">
    							<p><a href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a><p>
    								if ($enclosure = $item->get_enclosure())
    									{ ;?>
    									<p><?php echo $enclosure->embed();?></p>
    							<?php		}

    Refreshing the page sometimes resolves this issue, but obviously not a solution. Any help or advice would be greatly appreciated. This did not show up on my localhost while testing.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I have since added:

    if (!is_wp_error( $afl_link ) ) {
    				$maxitems = $afl_link->get_item_quantity(20);
    					echo $afl_link->get_error_message();

    under the line :
    $afl_link = fetch_feed('');

    It seems that the issue is with a timeout. I am getting the following error message now.

    WP HTTP Error: Operation timed out after 10001 milliseconds with 0 bytes received

    This is doing my head in. Would appreciate any help if somebody has come across this before.

    Resolved the issue with some help of a friend.

    Needed to set the feed timeout parameter to be longer then 10seconds.

    This is done in the feed.php file which is found in the wp-includes folder.

    Should look like this:

    * Build SimplePie object based on RSS or Atom feed from URL.
    * @since 2.8
    * @param string $url URL to retrieve feed
    * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success
    function fetch_feed($url) {
       require_once (ABSPATH . WPINC . '/class-feed.php');
       $feed = new SimplePie();
       $feed->set_file_class('WP_SimplePie_File');   $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 43200, $url));
       do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
       if ( $feed->error() )
           return new WP_Error('simplepie-error', $feed->error())
       return $feed;
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fatal error: Call to undefined method WP_Error::get_item_quantity()’ is closed to new replies.