The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Advanced Custom Field – show image

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #164693

    I recently worked through some of Chris’ materials in the Lodge about advanced plugins – in particular Advanced Custom Fields. I am using it for a page specific image that cannot be in the body of the text. I really like this feature and can see all kinds of uses for it – as soon as I sort out how to properly extract the image from all the data it returns.

    The static image is displayed like this:

    <img src="/~baybr/images/bay_breeze_article_photo.jpg" alt="bay_breeze_article_photo">

    The recommended code for displaying an image is:

    <img src="<?php the_field('lead_photo'); ?>" alt="" />

    That returns the following:

    src="14, Apartment homes by the water., Get to Know Us, , , image/jpeg,, 715, 243, Array"

    What I need out of this is the src for the image and not all the other image data.

    In Chris’ tutorial on the Lodge, he offered this code as a solution for displaying the image, where ‘lead_photo’ is the name of the custom field:

        $the_query = new WP_Query(array(
        'post_type' => 'lead_photo',
        'posts_per_page' => 1
        while ($the_query->have_posts()) :
        <?php $storyImage = get_field('lead_photo'); ?>
        <img src="<?php echo $storyImage[url]; ?>" alt=""  >
      <?php endwhile; ?>

    Unfortunately this brings back nothing, so I am afraid I have missed something in the code.

    I would appreciate any assistance in sorting this out.



    Thank you Doc. Problem solved.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.