Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a feed link and I have to read all the elements of feed including credits, here is how the feed is displayed

    <![CDATA[Dave&#39;s Lawnmower Bish Bash]]>
  <pubDate>Mon, 30 Apr 2012 21:49:55 -0700</pubDate>
  <enclosure url="" type="video/quicktime" length="6289971"/>
  <media:content url="" fileSize="6289971" type="video/quicktime" duration="0" height="360" width="640"/>
  <media:thumbnail url="" height="360" width="640"/>
  <media:thumbnail url="" height="101" width="180"/>
  <media:credit role="client" scheme="urn:feeds-wiredrive-com:credits">
  <media:credit role="agency" scheme="urn:feeds-wiredrive-com:credits">
  <media:credit role="director" scheme="urn:feeds-wiredrive-com:credits">
    <![CDATA[David Wood]]>

I have used this code to read the content but can not get the all the credits with this code

$file   = file_get_contents(''); 
$xml    =  simplexml_load_string($file);

$doc = new DOMDocument();
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {
        $itemRSS = array ( 

                'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,                

                'guid' => $node->getElementsByTagName('guid')->item(0)->nodeValue,
    'content' => $node->getElementsByTagNameNS('', 'content')->item(0)->getAttribute('url'),
    'vwidth' => $node->getElementsByTagNameNS('', 'content')->item(0)->getAttribute('width'),
    'vheight' => $node->getElementsByTagNameNS('', 'content')->item(0)->getAttribute('height'),
    'thumbnail' => $node->getElementsByTagNameNS('', 'thumbnail')->item(0)->getAttribute('url'),
    'credit' => $node->getElementsByTagNameNS('', 'credit')->item(0)->getAttribute('role') 
        array_push($arrFeeds, $itemRSS);

How do I read all the credits of each item? Can anyone help me is finding solution for this? Thanks in advance

share|improve this question
this is more a php question than a wordpress one. – fischi May 4 '12 at 6:23
I don't think this should be closed. The OP is asking how to do it in WP. From his code you can see its not the correct way in WP. Someone could answer this by giving examples using the correct WP way of reading an XML feed. – Brady May 4 '12 at 7:50

2 Answers 2

up vote 6 down vote accepted

WordPress bundles and wraps SimplePie class for feed download, caching and processing. Retrieving namespaced data with it would be something like this:

$feed  = fetch_feed( '' );
$items = $feed->get_items();

foreach ( $items as $item ) {

    $credit = $item->get_item_tags( '', 'credit' );
    var_dump( $credit );

See fetch_feed() in Codex.

share|improve this answer
Thanks a lot @Rarst. It worked for me – user478 May 4 '12 at 12:44

anyway, if you do something like this:

$medias = $node->getElementsByTagName('media');
foreach ( $medias as $media ) {
    $media_items[] = $media->nodeValue;
$itemRSS = array (
    'medias' => $media_items,
    // all the stuff you did

you should get your results.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.