Forums

Custom Fields Image Problem (5 posts)

  1. TheIslander
    Member
    Posted 6 months ago #

    I've got a number of image URLs in custom fields on pages - I want to be able to display them in image tags.

    I'm using this:

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

    The result is an empty SRC tag:

    <img alt="sunset" src="" height="150" width="450" border="0">

    The custom field IS in fact returning the URL, but for some reason; it is not displaying. I used exit/var_dump to verify this.

    My functions file is empty, do I need any function code to allow custom fields? or to change any wordpress settings?
    How can I fix this?

    thanks,

  2. alchymyth
    The Sweeper
    Posted 6 months ago #

    try:

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

  3. TheIslander
    Member
    Posted 6 months ago #

    Hi alchmyth,
    The code you posted is in fact what I have written in the file, yet there are no results.

    any ideas?

  4. alchymyth
    The Sweeper
    Posted 6 months ago #

    the code that I posted is different from the code you posted - that is the only thing I can see;
    right $post->ID vs. wrong $post_id->ID

    please paste the full code of the template into a http://pastebin.com/ and post the link to it here.

  5. TheIslander
    Member
    Posted 6 months ago #

    [edit: I've solved it] thanks!

    For Future reference, the problem was as alch rightfully pointed out. $post instead of $post_id; also, one should use '' instead of "".

    thanks again!

Reply

You must log in to post.

About this Topic