GluePear
GluePear

Reputation: 7715

Simplepie get_permalink returns feed link instead of item link

I am using Simplepie to access this feed. I use SimplePie's get_permalink() method to get the link of each item in the feed. This works with other feeds, but with this one get_permalink() is returning the URL of the feed as a whole, rather than the URL of a particular item.

Code:

$feed = new Rss_lib();
$feed->set_feed_url($feed_array);
$success = $feed->init();
$feed->handle_content_type();

foreach($feed->get_items() as $item)
{
   $item_arr = array(
       'permalink'   => $item->get_permalink(),
       'title'       => $item->get_title(),
       'description' => $item->get_description(),
       'date'        => $item->get_date()
   );
   $return[] = $item_arr;
}

I want to receive the permalink of the item rather than the feed's URL.

Upvotes: 1

Views: 285

Answers (1)

Eborbob
Eborbob

Reputation: 1975

It looks like SimplePie has a bug with regards to this feed. To get the link for the item you just need to retrieve all links and then pick out the one you want. For the feed in your question the second link is the link you are after (using my version of SimplePie anyway, different versions might parse it differently).

$links = $item->get_links();
$link = $links[1];

Upvotes: 1

Related Questions