tags:

views:

318

answers:

4

I write this code

function get_feed(){

 // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://dorar.shamekh.ws/?feed=rss2');
$maxitems = 1;
$items = array_slice($rss->items, 0, $maxitems,false);
return $items;

}

ass a part of plugin for wordpress , its work fine in my local server , but when I upload it to my blog I get the message

Warning: array_slice() [function.array-slice]: The first argument should be an array in

php version in my local host : 5.2.6 php version in my site : 5.2.5

A: 

What about casting $rss->items as an array first:

function get_feed(){

 // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://dorar.shamekh.ws/?feed=rss2');
$maxitems = 1;
$rss->items = (array) $rss->items;
$items = array_slice($rss->items, 0, $maxitems,false);
return $items;

}
barfoon
it didn't work --
Waseem
+1  A: 

It seems from the documentation that $rss->items should already be an array. I'd guess that the RSS fetch is failing. Try:

if (is_array($rss->items)) {
  $items = array_slice($rss->items, 0, $maxitems,false);
} else { var_dump($rss->items); }
MagpieRSS combined with dorar.shamekh.ws' (use of/configuration of) Apache 1.3.41 is leading to a very bizarre behaviour: A "normal" HTTP request:
GET /feed/ HTTP/1.0
Host: dorar.shamekh.ws   

MagpieRSS's request:

GET /feed/ HTTP/1.0
User-Agent: MagpieRSS/0.72 (+http://magpierss.sf.net)
Host: dorar.shamekh.ws:80
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

Note the different 'Host' headers. When the port number is appended, as in MagpieRSS, the site returns a 301:

HTTP/1.1 301 Moved Permanently
Date: Fri, 22 May 2009 02:45:03 GMT
Server: Apache/1.3.41 (Unix) PHP/5.2.5 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_ssl/2.8.31 OpenSSL/0.9.7a
X-Powered-By: PHP/5.2.5
X-Pingback: http://dorar.shamekh.ws/xmlrpc.php
Last-Modified: Wed, 20 May 2009 22:03:05 GMT
ETag: "e591693fdf2d27ee7dae19e256db2f46"
Location: http://dorar.shamekh.ws/feed/
Connection: close
Content-Type: text/html
TML
When I try to load the given URL using MagpieRSS locally, I get:Warning: MagpieRSS: Failed to fetch http://dorar.shamekh.ws/?feed=rss2 (HTTP Response: HTTP/1.1 301 Moved Permanently
TML
NULL -------------
Waseem
yes its working now , i change the rss link and it work , but I'm still shocked because the old rss link work in my local server
Waseem
See above - I'm not really sure which end is at fault here, but the behaviour is at least explainable. :)
TML
A: 

It sounds like to me that when it is attempting to get the RSS it is failing. Perhaps fetch_rss uses file_get_contents which has been disabled for URLs.

Either that, or for some reason, the property $rss->items isn't an array for some reason.

alex
A: 

fetch_rss() it's deprecated. See: http://codex.wordpress.org/Function_Reference/fetch_rss

You must use fetch_feed()

Regards: Antonio

Antonio