JD009
JD009

Reputation: 49

get_post_meta in img src returning src

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?

Upvotes: 1

Views: 848

Answers (2)

Vasanthan.R.P
Vasanthan.R.P

Reputation: 1287

Try this code

<img alt="sunset" src="<?php echo get_post_meta($post->ID, 'bottom', true) ?>" height="150" width="450" border="0" />

I changed $post_id->ID to $post->ID. Thanks

Upvotes: 0

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

get_post_meta returns the field value itself. You are probably inserted the whole "img" tag in the field itself. Check you field.

Upvotes: 1

Related Questions