How to use force_feed with fetch_feed

I use the exact same code from WordPress codex here : https://codex.wordpress.org/Function_Reference/fetch_feed#Example

It works as intended with most external RSS i tried to use but for one of them i have the error

A feed could not be found at RSS-URL. A feed with an invalid mime type may fall victim to this error, or SimplePie was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.

I can’t find any information on how to use force_feed with the code $rss = fetch_feed('RSS-URL');, and i’m 100% sure the external rss code is valid. I think the problem from the RSS is the content type which is xml and not rss+xml.

Any help appreciated, thanks !

Solutions Collecting From Web of "How to use force_feed with fetch_feed"

If we peek into the fetch_feed() function we see the instantiation:

$feed = new SimplePie();

where the object is made accessible through the wp_feed_options hook via:

do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );

where $feed is passed by reference.

This means we can adjust that object instance through the hook, before the $feed->init() is called within fetch_feed().

I searched this site for examples for you and found only one here by @Firsh. that sets $feed->force_feed(true) through the wp_feed_options hook.