Home Forums General Issues Can't display specific size image


Can't display specific size image

  • Greetings,

    I’ve tried so many dang times to get this thing to work and I cannot. I just want to display the medium size of the images attached to the Custom Fields – repeater field. Sometimes, there’ll be only one and no repeat. So, i’ll add that conditional once I can get the images to show.

    Here be my non-working code:

    <div id="secondary" class="widget-area" role="complementary">
     <?php global $post;
     setup_postdata( $post ); 
     if(get_field('cs_ss_images')) { ?>
      <?php while(has_sub_field('cs_ss_images')):
      $image_id = get_sub_field('cs_ss_image'); 
      //print_r($image_id); ?>
      <li><img src="<?php echo wp_get_attachment_image_src( $image_id ); ?>"></li>
     <?php endwhile; ?>
    <?php } ?>

    P.S. I threw in the setup_postdata thing as a flier since it’s in the sidebar.

    Also, here are my settings for the field:
    *Field Label: Slider Image
    *Field Name: cs_ss_image
    *Field Type: Image
    Return Value: Image ID

    The only thing it outputs now is “857Array 1220Array”
    The numbers are the two applicable attachment IDs. I don’t know why it’s not returning the URLS of those attachments instead.

  • The title of this thread is a little misleading.
    Eventually I want to show a specific size.
    But I need to show any size first, then I’ll include the size parameter in the wp_get_attachment_image_src function.

  • Hi @johnnyriss

    2 things:

    1 Looking at the docs ( I can see that there is a 2nd param to the function called $size. You are not using this size. You should me using ‘medium’

    2. Further on the docs, it states that the returned value is not a URL to the image, but an array containing 3 bits of info. The first being the URL followed by the width and height.

    This is already covered in the documentation for the image field. Perhaps you could read up on the ACF docs?

    Hope that helps

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Can't display specific size image’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.