I'm trying to build a shortcode that would display latest feed items from multiple sources. The problem I'm facig is that I cannot get it to work as it isn't displaying anything.

I take the feeds from an input in the admin dashboard and they're put up in an input field like this:

http://feed1.com, http://feed2.com

function rss_posts_func( $atts ){

    $sidebar_rss_options = get_option( 'sidebar_rss_option_name' );
    $feed_1_0 = $sidebar_rss_options['feed_1_0']; // Get the values from the input (works good)
    $feeds = explode(', ', $feed_1_0);//building up an array of values

    for($i = 0; $i < count($feeds); $i++){
        $feeds[$i] = (string)"'".$feeds[$i]."'";//adding quotes around each feed link
    $afterfeed = implode(',',$feeds);  //build an array of feeds with quotes(tried without quotes and nothing)

    // $feed = fetch_feed(array('http://feed1.com', 'http://feed2.com')); //this works well

    $feed = fetch_feed(array($afterfeed));//fetch the items from all the feeds

       if (!is_wp_error( $feed ) ) :
            $maxitems = $feed->get_item_quantity(8);
            $rss_items = $feed->get_items(0, $maxitems);

      //display the items in a list    
         $content = '<ul class="rss-aggregator">';
        foreach($rss_items as $item) {
            $content .= '<li class="feed-item">';
            $content .= '<a href='.$item->get_permalink().'>';
            $content .= $item->get_title();
            $content .= '</a></li>';
        $content .= '</ul>';
        return $content;

I tried using compact instead of array here and still didn't work

$feed = fetch_feed(array($afterfeed));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.