WordPress.org

Ready to get started?Download WordPress

Forums

v2.2 upgrade causes rss_fetch error (foreach) (11 posts)

  1. daviding
    Member
    Posted 7 years ago #

    I upgraded from v2.1 to 2.2, and now have the following error:

    Warning: Invalid argument supplied for foreach() in /home/mysite1/public_html/blog/wp-content/themes/rc2005-850/sidebar.php on line 46

    I recall simply copying and modifying the code from http://codex.wordpress.org/Function_Reference/fetch_rss to get this to work. The code looked like:

    <h2>Recently on my other blog</h2>
    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss('http://mysite2.com/blog/index.php/feed/'); ?>
    <ul>
    <?php foreach ( $rss->items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>

    I note that the current example at http://codex.wordpress.org/Function_Reference/fetch_rss refers to rss.php rather than rss-functions.php . I've otherwise been trying small variations, but I'm not a natural PHP coder, so I might be missing something easy.

    Help!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    A "foreach" error there probably means that your other site did not return any results.

    Try this code instead:

    <h2>Recently on my other blog</h2>
    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss('http://mysite2.com/blog/index.php/feed/'); ?>
    <ul>
    <?php if (empty($rss->items)) echo "<li>No items</li>";
    else
    foreach ( $rss->items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>

    See if it shows "No items".

  3. daviding
    Member
    Posted 7 years ago #

    Thanks for the PHP help. This should definitely be an amendment to the example at http://codex.wordpress.org/Function_Reference/fetch_rss . Unfortunately, it seems to uncovered a bigger mystery with the v2.2 migration.

    If you look at my personal blog at http://daviding.com/blog , the error message is gone, and the bullet reads "No items". As you've instructed, the code in sidebar.php is now:

    <h2>Recently on coevolving.com</h2>
    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss('http://coevolving.com/blogs/index.php/feed/'); ?>
    <ul>
    <?php if (empty($rss->items)) echo "<li>No items</li>";
    else
    foreach ( $rss->items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>

    However, if I surf over to http://coevolving.com/blogs/index.php/feed/ , there clearly is content in that feed.

    There's a natural parallel experiment here, because in the opposite direction, I've got my professional blog at http://coevolving.com/blogs running v2.12, with the prior working code of ...

    <h2>Recently on daviding.com</h2>
    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss('http://daviding.com/blog/index.php/feed/'); ?>
    <ul>
    <?php foreach ( $rss->items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>

    ... and that seems to work just fine.

    So is this a problem with rss_fetch under WordPress v2.2? I'm deducing that the feed is fine, and the cause of the breakage was the migration from v2.12 to v2.2.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    What this is really saying is that the coevolving server could not retrieve the feed, not that the feed is not there. There could be a lot of reasons for this.

    Are these websites on the same server? Same configuration? Do other RSS feed URLs work on that site?

  5. daviding
    Member
    Posted 7 years ago #

    Yes, both web sites are on the same server. They run WordPress in parallel, and I normally upgrade all installations one after the other to keep things simple. (Actually, there's a third blog, too).

    Checking the site right now, all four feeds are working: http://coevolving.com/blogs/index.php/feed/ , http://coevolving.com/blogs/index.php/feed/rdf/ , http://coevolving.com/blogs/index.php/feed/rss/ and http://coevolving.com/blogs/index.php/feed/atom/ .

  6. daviding
    Member
    Posted 7 years ago #

    I don't think that this is a case where the coevolving.com server (running WordPress v2.12) is not providing the feed; it's a case where the rss_fetch on the daviding.com server (running WordPress v2.2) is not picking up the feed.

    In the case that this problem was caused by a weird interaction with some other plugin, I deactivated almost all of them (removing WordPress E-mail Notification causes an error in header.php), but the result remains unchanged. The feed says "no entries".

  7. daviding
    Member
    Posted 7 years ago #

    I think that this problem is a real bug, and have reposted it at http://trac.wordpress.org/ticket/4495 .

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    I doubt that this is an actual bug for a very simple reason: The rss.php file (where fetch_rss and such are) did not actually change between 2.1.3 and 2.2. Compare them yourself, they are identical.

    This is far more likely to be a configuration problem.

    Can the problem server actually resolve the "coevolving.com" name into the correct IP? Do other feed addresses from other servers/websites work?

    If the problem really is in the fetch_rss functions, then NO feeds would work, right? Well, the main dashboard screen uses that functionality to display the "WordPress Development Blog" stuff as well as the "Incoming Links" stuff. Do those show up on your site?

  9. daviding
    Member
    Posted 7 years ago #

    Yes, the "WordPress Development Blog" stuff shows up.

    On your suggestion, I have copied-and-pasted the code to include a feed of this support topic on the sidebar:

    <h2>Recently on coevolving.com</h2>
    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss('http://coevolving.com/blogs/index.php/feed/'); ?>
    <ul>
    <?php if (empty($rss->items)) echo "<li>No items</li>";
    else
    foreach ( $rss->items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>
    
    <h2>A thread on fetch_rss</h2>
    <?php require_once(ABSPATH . WPINC . '/rss-functions.php'); ?>
    <?php $rss = fetch_rss('http://wordpress.org/support/rss/topic/122141'); ?>
    <ul>
    <?php if (empty($rss->items)) echo "<li>No items</li>";
    else
    foreach ( $rss->items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>

    So, you're right, at http://daviding.com/blog , the feed from http://coevolving.com/blogs/index.php/feed/ finds "No items", but the feed from http://wordpress.org/support/rss/topic/122141 does.

    Yet, when I paste http://coevolving.com/blogs/index.php/feed/ into my browser, the feed comes right up.

    In addition, I have now pasted the same rss_fetch code into sidebar.php for http://systemicbusiness.org/blog (which is a sister web site for the other two). The feed from coevolving.com shows up on systemicbusiness.org (a WordPress v2.1.2 site) but not on daviding.com (a WordPress v2.2 site). All three web sites are on the same server.

    Where else would you suggest that I look, as a "configuration problem"?

  10. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    I don't know. I don't claim to have the answers, I am just not so quick to call it a bug in the rss code, which has remained essentially unchanged for several iterations of WordPress.

    Here's the change history:
    http://trac.wordpress.org/log/trunk/wp-includes/rss.php

  11. daviding
    Member
    Posted 7 years ago #

    I've now upgraded the two other blogs from v2.12 to v2.2. Strangely enough, the problem has disappeared.

    There must be some strange interaction bug by reading feeds from different versions of WordPress. That closes this issue ... although it's still a mystery!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags