Fatal error: Call to a member function getElementsByTagName() WordPress 4.2.2 RSS Feed

268 views Asked by At

I'm getting Fatal error: Call to a member function getElementsByTagName() now when I'm trying to pull in the RSS feed from my wordpress blog. Here's the code I'm using to get the RSS feed (which has worked up until recently):

$xmlDoc = new DOMDocument();
        @$xmlDoc->load('http://www.revolutionpersonaltraining.com.au/blog/feed/');
        $x      = $xmlDoc->getElementsByTagName('item');

        for ($i=0; $i<6; $i++):
            $items[$i]['date']  = strftime("%Y-%m-%d %H:%M:%S", strtotime($x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue));
            $items[$i]['title'] = $x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
            $items[$i]['link']  = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
            $items[$i]['desc']  = $x->item($i)->getElementsByTagName('encoded')->item(0)->childNodes->item(0)->nodeValue;
        endfor;

If anyone could shed any light on this, that would be fantastic.

1

There are 1 answers

3
Deep Kakkar On BEST ANSWER

You can use this way :

$feed = new DOMDocument();
$feed->load('http://www.revolutionpersonaltraining.com.au/blog/feed/');


$items = array();
foreach ($feed->getElementsByTagName('item') as $item) {
    array_push($items, array ( 
        'title' => $item->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $item->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $item->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $item->getElementsByTagName('pubDate')->item(0)->nodeValue,
    ));
}

Good Luck