I’m developing a wordpress theme and using custom fields. I’ve got the following code:
<img alt="sunset" src="<?php echo get_post_meta($post_id->ID, 'bottom', true) ?>" height="150" width="450" border="0" />
// That code is giving this:
<img alt="sunset" src="" height="150" width="450" border="0">
I used this code to check if the custom field is empty, it returns the path to the image which is correct, the image works properly when viewed using that path.
<?php exit ( var_dump( get_post_meta($post->ID, 'bottom', true) ) ); ?>
Any ideas to why the image is not displaying correctly?
get_post_meta returns the field value itself. You are probably inserted the whole “img” tag in the field itself. Check you field.
Try this code
I changed $post_id->ID to $post->ID. Thanks