Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I pass feed URLs with & in the URL to fetch_feed()?

The feed is not parsed correctly if there is a & in the feed URL. Actually it works in the example I gave, but now I'm populating the feeds array dynamically with this code :

$rss_subscriptions = array();
$terms = get_terms('news_rss','hide_empty=0');
$count = count($terms);
if($count > 0){
    foreach ($terms as $term) {
        array_push($rss_subscriptions,$term->description);
    }
}

The RSS feeds URLs are stored in the descriptions of the taxonomy news_rss terms. Somehow in this code, passing & into the array makes the fetch_feed($array) not work.


Original question: fetch_feed() on multiple feeds, how to pass the feeds array properly ?

Hi, this is too weird, perhaps someone can explain what is going on here.

Why does this :

$feeds = array('http://www.mysite.com/feed','http://www.coolsite.net/feed');
$result = fetch_feed($feeds);

return a different result than this :

$result = fetch_feed(array('http://www.mysite.com/feed','http://www.coolsite.net/feed'));

Actually, the second example works, the first one returns feed items, but for some reason they are not the last ones...

I want to find a way to populate the feeds array dynamically, that's why I'd like something like the first example better.

share|improve this question
    
It would help if you provided example of specific public (if available) URL that causes the issue. –  Rarst Apr 5 '11 at 19:44

3 Answers 3

Further to my comment above, I think it is probably to do with the & being converted into & or &.

I had this problem and ended up solving it by running the URL though wp_specialchars_decode before passing it to fetch_feed.

I'd suggest you try this (although so much time has passed that I'm really writing this for people who stumble across this page via Google as I did).

I've written up my problem over here, in case it helps: http://scratch99.com/wordpress/development/fetch_feed-url-problem/

share|improve this answer

If anyone is still wondering about this:

If you're using fetch_feed inside a shortcode, chances are you've hit the bug Stephen described.

However, SimplePie 1.2 had a bug where URLs were incorrectly encoded before the HTTP request was made. This is the most likely cause of your error. WordPress now uses 1.2.1, however, where this bug should be fixed.

share|improve this answer

Two methods you use should be identical from PHP viewpoint, I do not see in code any passing by reference or something else that could make a difference.

but for some reason they are not the last ones

By default there is very considerable caching time 43200 seconds (12 hours). Could it be that this is what getting you undesirable results?

share|improve this answer
    
Ok, here's what I found. The feed is not parsed correctly if there is a "&" in the feed URL. Actually it works in the example I gave, but now I'm populating the feeds array dynamically with this code : $rss_subscriptions = array(); $terms = get_terms('news_rss','hide_empty=0'); $count = count($terms); if($count > 0){ foreach ($terms as $term) { array_push($rss_subscriptions,$term->description); } } The RSS feeds URLs are stored in the descriptions of the taxonomy "news_rss" terms. Somehow in this code, passing "&" into the array makes the fetch_feed(array) not work. –  mike23 Mar 30 '11 at 17:10
    
@mike23 don't think I have any experience with & in feed URLs, you might need to pass it through htmlspecialchars() or something. –  Rarst Mar 30 '11 at 17:20
    
@mike23: I have rewritten your question because it is a different question now. For clarity: Rarst responded to the original question, which is still available above. –  Jan Fabry Apr 5 '11 at 12:09
    
I'm guessing the problem is that the & is being converted into & - that's what's happening for me... –  Stephen Cronin Nov 28 '11 at 3:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.