I'm trying to have a little section on my wordpress home page that has a RSS feed of my blogs activity.

Here is my code for getting and displaying the RSS

<?php // Get RSS Feed(s)     
include_once( ABSPATH . WPINC . '/feed.php' );

// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'http://www.wpbeginner.com/feed/' );

if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly

// Figure out how many total items there are, but limit it to 5. 
$maxitems = $rss->get_item_quantity( 5 ); 

// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );


<?php if ( $maxitems == 0 ) : ?>
        <li><?php _e( 'No items', 'my-text-domain' ); ?></li>
    <?php else : ?>
    <?php // Loop through each feed item and display each item as a hyperlink. ?>
    <?php foreach ( $rss_items as $item ) : ?>
             <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
                                title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">

        <?php echo esc_html( $item->get_title() ); ?>
    <div class="rssinfo">

    <?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>
    <?php endforeach; ?>
<?php endif; ?>

Now this feed works. The thing is that the blogurl isn't my blog. Now if I try and switch the url over to my feed, any variation of the url doesn't work. It shows up No Items.

Some of the URLs I tried:

obrienservice.com/feed obrienservice.com/feed/rss obrienservice.com/?feed=rss2

If you check the above URLs, you'll see the RSS feed IS being generated. I just don't know why it won't go through my script.

  • can you provide debug information? e.g. you're checking if the feed is not a WP Error, but if it IS a wp error, you output no message. If you could get us said message? – Tom J Nowell Apr 15 '14 at 19:03
  • How do I do this? – user2444539 Apr 15 '14 at 19:07
  • you're doing $rss = fetch_feed(...); if ( !is_wp_error($rss) ) { ..do stuff.. } but what if you then put: else { .. but what if it IS a wp error?.. } see the WP_Error documentation for how to call getMessage or whatever the method is called, there'll be examples. You'll need the error message to know what went wrong so we can answer the question – Tom J Nowell Apr 15 '14 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.