WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm learning how to write a shortcode. I'm getting this error: Parse error: syntax error, unexpected T_FOREACH . I'm having problems with concatenating it properly.

Plugin Name:  My Plugin
Plugin URI: http://mysite.com
Description: This does blah
Version: 1.0
Author URI: http://www.mysite.com

function csf_cap_databaseinfo() {
    global $wpdb;

    $greeting = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_test;")); 

     $out = '<table>

      $out .=  foreach ($greeting as $greet){ .'<tr><td>' . echo $greet->id . '</td></tr>' . } .'</table>'; 

        return $out; 


add_shortcode('db-info', 'csf_cap_databaseinfo');

Any suggestion on how to fix this error? Thank you.


share|improve this question
up vote 1 down vote accepted


$out .=  foreach ($greeting as $greet){ .'<td>' . echo $greet->id . '</td>' . } .'</table>';


foreach ($greeting as $greet){ $out .=  '<td>' . $greet->id . '</td>'; } 
$out .=  '</table>';  
share|improve this answer
Hi Michael, Thank you for the help. It works! – Laxmidi Aug 30 '11 at 0:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.