Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:41:07+00:00 2026-06-16T02:41:07+00:00

I am building a wordpress plugin for learning reasons and this is the code

  • 0

I am building a wordpress plugin for learning reasons and this is the code in question:

// display latest facebook posts
// Init a cURL resource
$ch = curl_init("https://www.facebook.com/feeds/page.php?format=rss20&id=133869316660964");
curl_setopt( $ch, CURLOPT_POST, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
// Make facebook think it is being accessed by a browser to avoid compatability issues
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$data = curl_exec( $ch );

// instanciate a new xml element
$fb = new SimpleXMLElement($data);
$i = 0; // set the counter for the foreach loop to 0

echo "<ul>"; // begin the UL

foreach ($fb->channel->item as $item) {
    // foreach item within the tree perform this loop twice
    $link = $item->link; // set the link address
    $post = $item->description; // set the post data
    echo "<li>" . $post, ' :::::: ', '<a href="' . 
    $link . '">' . $link, PHP_EOL . "</a></li>";
    $i++;
    if($i == 2){
        exit();
    }
}
echo "</ul>";

However when I inspect the HTML I see this: (quick snippet from the very bottom)

846656&id=133869316660964
</a></li>

This is the last part of the foreach loop where $i =< 2 so using exit appears to be stopping the script totally, am I correct in saying that or is there another error causing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:41:08+00:00Added an answer on June 16, 2026 at 2:41 am

    exit(); stops php execution. Try using break; to exit the loop

    PHP break

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a plugin for WordPress 3.3.1. In the code I define several
I am building a wordpress site using jQuery with cycle plugin to cycle through
This is fairly simple but I cant work it out. I'm building a wordpress
I'm building a plugin to WordPress and so far so good with the PHP
I'm building a custom WordPress theme and have a quick question regarding WordPress and
Here's the scenario: I'm building a Wordpress plugin to manage some survey research that
I'm using working on building a WordPress plugin, that uses the Twitter api -
I'm building a website using WordPress and am wondering if its possible to display
I'm building a WordPress plugin using PHPExcel to export reports of student attendance. So
I'm building Wordpress website where all content pages are loaded using Ajax. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.