• Resolved Drew Baker

    (@dbaker)


    Hi Guys,
    I’m trying to pull in content from a mRSS feed. This is an example of the mRSS item:

    <item>
    	<title><![CDATA[Title Example]]></title>
    	<link>https://example.com/</link>
    	<guid>https://example.com/</guid>
    	<description><![CDATA[movie.mov
    	<br /><img src="https://example.com/image.jpg" />]]></description>
    
    	<pubDate>Fri, 1 Dec 2009 00:42:21 +0000</pubDate>
    	<enclosure url="https://example.com/movie.mov" type="video/quicktime" length="5319922"/>
    	<media:content url="https://example.com/movie.mov" fileSize="5319922" type="video/quicktime" height="270" width="480"/>
    	<media:thumbnail url="https://example.com/big_thumb.jpg" height="480" width="640"/>
    	<media:thumbnail url="https://example.com/small_thumb.jpg" height="135" width="180"/>
    	<media:credit role="client">Client</media:credit>
    	<media:credit role="director">John Doe</media:credit>
    	<media:credit role="agency" >Agency Example</media:credit>
    	<media:credit role="production company">Example Production Company</media:credit>
    	<media:credit role="award winner">Example Award</media:credit>
    </item>

    My question is, how do I get to the media:content url? I’m using this code, but it doesn’t work:

    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/feed.php');
    
    // Get a SimplePie feed object from the specified feed source.
    $rss = fetch_feed('https://www.example.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);
    endif;
    ?>
    
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
        foreach ( $rss_items as $item ) : ?>
    
    	<a href="<?php echo $media->content->attributes()->url; ?>">Test</a>
    
    <?php endforeach; ?>

    I get this error:

    Fatal error: Call to a member function attributes() on a non-object…

    I know I’m doing doing this line wrong:
    $media->content->attributes()->url

    What is the correct syntax?

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter Drew Baker

    (@dbaker)

    I figured it out. The confusing thing is that the SimplePie API treats the <media> namespace as <enclosure>.

Viewing 1 replies (of 1 total)
  • The topic ‘SimplePie mRSS – Get at media:content URL?’ is closed to new replies.