• Resolved thesaviour

    (@thesaviour)


    This maybe a stretch as I have looked far and wide for an answer, but can’t seem to find one.

    It’s for a mapping tool and I am looking for a code which will display an image based on a custom field value.

    For example, if the custom field value (called “map_location”) was “A1” it should display image “A1.jpg”. If the custom field value was “B2” it should display image “B2.jpg”…you get the idea.

    I tried several ways, but they all seem to kick-up an error of some kind or no output. Some help on this would be great appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    $field = get_post_meta($post->ID, 'YOURFIELDNAME', true);
    if($field) { ?>
    <img src="some/path/to/images/<?php echo $field; ?>.jpg" border="0" alt="" />
    <?php }
    ?>

    $field is the value in the custom field..

    Update YOURFIELDNAME to the actual field name..

    This of course should be used in the loop, if required outside the loop you’ll need to provide an example of the code you want to use it with.

    Thread Starter thesaviour

    (@thesaviour)

    Thank you so much t31os_. Your code is exactly what I was looking for.

    Many thanks.

    You’re welcome. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom field value output based on another value’ is closed to new replies.