0
votes

Hi all this is wordpress php question I am trying to get thumbnail from custom field image. Please help me with the code thank you so much.

<?php
if (get_post_meta($post->ID, 'thumbnail', true)) {
echo "<img src='echo get_post_meta($post->ID, 'thumbnail', true)' width='100px' />";
}else{
echo "<img src='http://site.com/default.jpg' width='50px' />";
}   
?>

Above code results default pic where custom field image is not added but is giving out img code shown below as output for custom filled image.

<img src='echo get_post_meta(86, ''thumbnail'', true)' width='100px' />
1

1 Answers

1
votes

The problem most likely is that you have an echo statement inside another echo statement.

<?php
if (get_post_meta($post->ID, 'thumbnail', true)) {
echo "<img src='" . get_post_meta($post->ID, 'thumbnail', true) . "' width='100px' />";
}else{
echo "<img src='http://site.com/default.jpg' width='50px' />";
}   
?>