Support » Plugin: Simple Fields » [Plugin: Simple Fields] Showing image by field title

  • mrengy

    (@mrengy)


    I am able to show an image from a custom field using the code example at Tips and Tricks:

    <?php
    $image_id = get_post_meta(get_the_ID(), "_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0", true);
    $img_src = wp_get_attachment_url($image_id, 'thumbnail');
    ?>
    <img src="<?php echo $img_src ?>" alt="An image" />

    However, when attempting to show the image using the title of the field rather than the ID, it doesn’t display. Is it possible to do something like:

    <?php
    $image_id = get_post_meta(get_the_ID(), "IMAGE-FIELD-TITLE", true);
    $img_src = wp_get_attachment_url($image_id, 'thumbnail');
    ?>
    <img src="<?php echo $img_src ?>" alt="An image" />

    ?

    This would be incredibly helpful as I am working across three servers (production, staging, and development), and this would allow me to avoid having to change the IDs for all custom image fields with each migration.

    http://wordpress.org/extend/plugins/simple-fields/

  • The topic ‘[Plugin: Simple Fields] Showing image by field title’ is closed to new replies.