Support » Fixing WordPress » fetch_feed: retrieve entries in the appearing order, not chronologically

  • Resolved MultiformeIngegno

    (@lorenzone92)


    I’m using WP function fetch_feed to retrieve a feed and display its items.

    <?php
            /* include the required file */		include_once(ABSPATH . WPINC . '/feed.php');
            /* specify the source feed   */		$rss = fetch_feed('http://stackoverflow.com/feeds/user/1342772');
            /* checks obj. is created	 */		if (!is_wp_error( $rss ) ) :
            /* specify number of items   */		$maxitems = $rss->get_item_quantity(4);
            /* create an array of items  */		$rss_items = $rss->get_items(0, $maxitems);
        endif;
            ?>
            <ul>
                <?php if ($maxitems == 0) echo '<li>Il contenuto non รจ disponibile.</li>';
            else
                // Loop through each feed item and display each item as a hyperlink.
                foreach ( $rss_items as $item ) : ?>
                    <li>
                        <a href="<?php echo $item->get_permalink(); ?>" title="<?php echo esc_html( $item->get_title() ); ?>" rel="external"><?php echo esc_html( $item->get_title() ); ?></a>
                    </li>
                    <?php endforeach; ?>
            </ul>

    If I visit the feed in question with (e.g.) Firefox, I see the entries in the XML appearing order. fetch_feed retrieves the most recent instead (according to their <published> tag). How can I make sure it retrieves items according to their order on the XML feed (not chronologically)

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘fetch_feed: retrieve entries in the appearing order, not chronologically’ is closed to new replies.