Quantcast
Channel: Why does Simplepie return feed items in a wrong order? - WordPress Development Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by birgire for Why does Simplepie return feed items in a wrong order?

$
0
0

I think you simply have to replace:

$feed->enable_order_by_date(false);

with

$rss->enable_order_by_date(false);

to disable the descending date ordering.

In the case of a feed error, the fetch_feed() function returns an instance of the \WP_Error class. Otherwise the output is an instance of the \SimplePie class and this class contains the enable_order_by_date() public method.

So you should use it like this:

// Fetch the feed:
$rss = fetch_feed( $feed_url );

// Make sure we don't have and WP_Error instance:
if ( ! is_wp_error( $rss ) )   
{
    // Disable the date ordering:
    $rss->enable_order_by_date( false );

    // ... etc ...
}

where we (implicitly) make sure we have an instance of the \SimplePie class.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>