Support » Plugin: Easy Facebook Feed » Pull feeds from multiple pages

  • Resolved Alex


    Thanks for the plugin, it’s 1000 times better than dated and bogus “Custom Facebook feed” plugin.

    Anyway, here’s how to make it pull feeds from multiple pages and organize posts by date.

    $shortcode_atts = shortcode_atts( array(
    	'id' => $options['facebook_page_id'],
    	'limit' => $options['facebook_post_limit'],
    ), $atts );
    $shortcode_atts['id'] = array_map('trim', array_filter(explode(',', $shortcode_atts['id'])));
    foreach( $shortcode_atts['id'] as $id )
    	$feed = self::eff_get_page_feed($id, $shortcode_atts['limit']);
    	$page = self::eff_get_page($id);
    	if(isset($feed->error)) {
    		return self::eff_makeError($feed->error->message);
    	if(isset($page->error)) {
    		return self::eff_makeError($page->error->message);
    	foreach ($feed->data as $key => $data) {
    		$postTemplate = self::eff_makePost($data, $page);
    		switch ($data->type) {
    			case 'photo':
    				$photoTemplate = self::eff_makePhoto($data);
    				$items[$data->created_time] = Template::merge($postTemplate, $photoTemplate);
    			case 'link':
    				$linkTemplate = self::eff_makeLink($data);
    				$items[$data->created_time] = Template::merge($postTemplate, $linkTemplate);
    			case 'video':
    				$videoTemplate = self::eff_makeVideo($data);
    				$items[$data->created_time] = Template::merge($postTemplate, $videoTemplate);
    			case 'event':
    				$eventTemplate = self::eff_makeEvent($data);
    				$items[$data->created_time] = Template::merge($postTemplate, $eventTemplate);
    			case 'status':
    				$postTemplate = str_replace("{{data-content}}", '', $postTemplate);
    				$items[$data->created_time] = $postTemplate;
    add_filter( 'jetpack_photon_skip_image', array( 'Eff', 'eff_photon_exception'), 10, 3 );
    $items = array_slice($items, 0, $shortcode_atts['limit']);
    return implode('', $items);
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Alex


    BTW to make things even smoother we need to cache the feeds

    $cacheKey = md5('eff'.serialize($shortcode_atts));
    if( $cachedFeed = get_transient($cacheKey) )
    {	// Return cached feed
    	return $cachedFeed;
    /* foreach() & krsort() etc.  */
    // Save to cache for 30 minutes
    set_transient($cacheKey, $items, 1800);
    return $items;
    • This reply was modified 4 years, 9 months ago by Alex.
    Plugin Author Tim


    Hi Alex,

    Glad you like it and thanks for the suggestions, I specially like the caching solution. I’ll take a closer look at it coming weekend and will update the code.

    Plugin Author Tim


    I added your code and did some testing, works great. Its included in version 2.4, thanks!

    Thread Starter Alex


    Thanks for adding the changes

    There’s a problem though, you need to check and return cached feeds BEFORE you do the “foreach” loop. Otherwise there’s no sense in having it cached.

    Also there’s no need to run implode('', $cachedFeed); twice, just implode the items before you save them to cache, and then return the results as is.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pull feeds from multiple pages’ is closed to new replies.