Title: Problem with RSS feeds. array_alice error
Last modified: August 19, 2016

---

# Problem with RSS feeds. array_alice error

 *  [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/)
 * I have a strange problem with pulling in RSS entries from a feed. Most of the
   times I get this error on the page, but after reloading, it works. Obviously,
   the best thing would be for it never to show the error and just reload automatically
   when there was a problem.
 * This is the error code i get in the browser:
    `Warning: array_slice() expects
   parameter 1 to be array, null given in /home3/kasperso/public_html/wp-content/
   themes/mechatronics/page_media.php on line 14`
 * Here are the lines 11-18 in the file page_media.php
 *     ```
       <?php
       		include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
       		$feed = fetch_rss('http://pipes.yahoo.com/pipes/pipe.run?_id=e49a6cfb219f8180ded1313941be1808&_render=rss'); // specify feed url
       		$items = array_slice($feed->items, 0, 5); // specify first and last item
       		?>
   
       		<?php if (!empty($items)) : ?>
       		<?php foreach ($items as $item) : ?>
       			<div class="post">
       			<h1 class="post-title"><a>"><?php echo $item['title']; ?></a><?php edit_post_link(' EDIT', '<span>', '</span>'); ?></h1>
       			<?php if (isset($item['description'])) : ?>
       			<div class="entry"><?php echo $item['description']; ?></div>
       			<?php endif; ?>
       			</div>
   
       			<?php endforeach; ?>
       		<?php endif; ?>
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635176)
 * No one in here either?
 *  Thread Starter [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635195)
 * Anyone know who I could contact about this problem?
 *  Thread Starter [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635222)
 * This is actually still a problem, if anyone have any input.
 * A contact name or email address would be fine, as we can pay for fixing this.
 *  [Curtiss Grymala](https://wordpress.org/support/users/cgrymala/)
 * (@cgrymala)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635223)
 * Well, you could keep it from giving you an error by checking to make sure $feed
   really is an array before trying to use it. That would look like:
    `$items = (
   is_array( $feed->items ) ) ? array_slice($feed->items, 0, 5) : NULL;`
 * If you do that, though, you probably also need to check to make sure the `$feed`
   variable is an object, and that it includes the `items` property. Then, your 
   code would look more like:
 *     ```
       if( is_object( $feed ) && property_exists( $feed, 'item' ) && is_array( $feed->items ) ) {
         $items = array_slice($feed->items, 0, 5);
       }
       ```
   
 * Of course, by running these checks, that means that, instead of seeing the error,
   you’ll just see no output. You could add in some extra code that outputs something
   like: “There was an error displaying this information. Please try reloading the
   page.” if `$items` ends up being empty.
 * That doesn’t solve the larger problem, though, which is that your Pipes feed 
   doesn’t seem to be sending the right information on the first try.
 *  Thread Starter [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635224)
 * Woow thanks. Patience paid off. I will implement it now.
 *  Thread Starter [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * (@kasperbs)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635225)
 * It now looks like this.
 *     ```
       <?php
       		include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
       		$feed = fetch_rss('http://pipes.yahoo.com/pipes/pipe.run?_id=e49a6cfb219f8180ded1313941be1808&_render=rss'); // specify feed url
       		if( is_object( $feed ) && property_exists( $feed, 'item' ) && is_array( $feed->items ) ) {
         		$items = array_slice($feed->items, 0, 5); } // specify first and last item
       		?>
   
       		<?php if (!empty($items)) : ?>
       		<?php foreach ($items as $item) : ?>
       			<div class="post">
       			<h1 class="post-title"><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a><?php edit_post_link(' EDIT', '<span>', '</span>'); ?></h1>
       			<?php if (isset($item['description'])) : ?>
       			<div class="entry"><?php echo $item['description']; ?></div>
       			<?php endif; ?>
       			</div>
   
       		<?php endforeach; ?>
       		<?php endif; ?>
       		<?php if (empty($items)) : ?>
       		<p><em>Der blev ikke fundet nogen aktuelle nyheder på de søgte medier.</em></p>
       		<?php endif; ?>
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Problem with RSS feeds. array_alice error’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [kasperbs](https://wordpress.org/support/users/kasperbs/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/problem-with-rss-feeds-array_alice-error-1/#post-1635225)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
