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.


1 Answer 1



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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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