Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:
Description: This does blah
Version: 1.0
Author URI:

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

1 Answer 1

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.