[resolved] fetch_feed: retrieve entries in the appearing order, not chronologically (3 posts)

  1. MultiformeIngegno
    Posted 3 years ago #

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

            /* 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);
                <?php if ($maxitems == 0) echo '<li>Il contenuto non รจ disponibile.</li>';
                // Loop through each feed item and display each item as a hyperlink.
                foreach ( $rss_items as $item ) : ?>
                        <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>
                    <?php endforeach; ?>

    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)

  2. MultiformeIngegno
    Posted 3 years ago #

    Finally found the solution (hope this can help others!):


    It should DEFINITELY be added to the fetch_feed(); documentation.

  3. bswen
    Posted 2 years ago #

    Wow, was banging my head on this one. Doing a print_r on the feed object shows them in the XML order, so the reordering by publication date is not even apparent there.

    Thanks for posting, and, agreed, the fact that WP orders the feed by publication date should be made explicitly clear on the fecth_feed codex page.

    Just to record the command found at stackexchange here:

    /* specify the source feed   */  $rss = fetch_feed('FEED_URL');
     /* disable order by date     */  $rss->enable_order_by_date(false);

Topic Closed

This topic has been closed to new replies.

About this Topic