Support » Fixing WordPress » Adding get meta data to a loop

  • Resolved martcol


    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



Viewing 3 replies - 1 through 3 (of 3 total)
  • $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

    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



Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding get meta data to a loop’ is closed to new replies.