Title: Adding get meta data to a loop
Last modified: August 20, 2016

---

# Adding get meta data to a loop

 *  Resolved [martcol](https://wordpress.org/support/users/hotmale/)
 * (@hotmale)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/adding-get-meta-data-to-a-loop/)
 * If I add either of the following statments in the loop it works out OK
 *     ```
       echo get_post_meta($post->ID, 'phone', true);
   
       $key2="phone"; echo get_post_meta($post->ID, $key2, true);
       ```
   
 * If I add this in the same place it goes pear-shaped and gives me an error: syntax
   error, unexpected T_VARIABLE, expecting ‘,’ or ‘;’
 *     ```
       $phone = get_post_meta($post->ID, 'phone', true);
       if ($phone) {
       echo '<div class="sideBox">'$phone'</div>';
       }
       ```
   
 * Can someone please try and tell me why the second option doesn’t work. I guess
   you can see that I want to call this custom field meta data but wrap it in some
   HTML
 * Thanks
 * Martin

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Justin](https://wordpress.org/support/users/jgwpk/)
 * (@jgwpk)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/adding-get-meta-data-to-a-loop/#post-3638346)
 *     ```
       $phone = get_post_meta($post->ID, 'phone', true);
       if ($phone) {
       echo '<div class="sideBox">'.$phone.'</div>';
       }
       ```
   
 * You are missing the periods in the echo statement
 *  Thread Starter [martcol](https://wordpress.org/support/users/hotmale/)
 * (@hotmale)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/adding-get-meta-data-to-a-loop/#post-3638400)
 * Justin, thank you for that. I can’t try it out until the morning Zzzzzzz
 * Can I just ask why it doesn’t work without the period? Is that a concatenation
   thing and if it is, is it like sticking things together or keeping them apart?
 * Thank again, I can’t wait to give it a go
 * Martin
 *  Thread Starter [martcol](https://wordpress.org/support/users/hotmale/)
 * (@hotmale)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/adding-get-meta-data-to-a-loop/#post-3638465)
 * Terrific!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding get meta data to a loop’ is closed to new replies.

## Tags

 * [custom_field](https://wordpress.org/support/topic-tag/custom_field/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [martcol](https://wordpress.org/support/users/hotmale/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/adding-get-meta-data-to-a-loop/#post-3638465)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
