Search code examples
phpsimplepie

Simplepie, how to get the url feed inserted


I am using this plugin for my website and I am struggling with problem I have. I use a multifeed system and the code looks like this :

$feed = new SimplePie();
$feed->set_feed_url($feedsArray);
$feed->init();
$feed->handle_content_type();
$feed->set_item_limit(50);

foreach ($feed->get_items() as $item){

     $data[] = array( 'title' => $item->get_title(), 'description' => $item->get_description() );

}

Everything works perfectly but, what I want is to introduce in the $data array a value like "feedUrl" which is the url used in $feedsArray for the actual item. Remember this array contains all the urls and I want the url used for the actual item where I get news.

Sorry if my explanation is a bit confusing,

Thanks in advance!


Solution

  • Use $feed->get_permalink(); for the feed's link or $item->get_permalink(); for the item's permalink.

    Update

    Use 'feedUrl' => $item->get_base('href'):

    foreach ($feed->get_items() as $item) {
    
         $data[] = array( 'feedUrl' =>  $item->get_base('href'), 'title' => $item->get_title(), 'description' => $item->get_description() );
    
    }