Skip to content

Instantly share code, notes, and snippets.

@thoronas
Created August 30, 2013 22:08
Show Gist options
  • Save thoronas/6394780 to your computer and use it in GitHub Desktop.
Save thoronas/6394780 to your computer and use it in GitHub Desktop.
ACF Image function
<?php $image = wp_get_attachment_image_src(get_field('image'), 'medium'); ?>
<img src="<?php echo $image[0]; ?>">
@crondeau
Copy link

I'm using this in my repeater field:

<ul>
<?php while( has_sub_field( 'whatwedo' ) ): ?>
    <?php $image = wp_get_attachment_image_src( the_sub_field( 'what_image' ), 'video' ); ?>             

    <li>
    <img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>"><p><?php //the_sub_field( 'what_description' ); ?></p>
    </li>

    <?php endwhile; ?>
    </ul>

All I get is a number in return. :(

@jkudish
Copy link

jkudish commented Aug 30, 2013

Unrelated to the issue at hand; this has some output escaping issues, should read:

<img src="<?php echo esc_url( $image[0] ); ?>" width="<?php echo esc_attr( $image[1] ); ?>" height="<?php echo esc_attr( $image[2] ); ?>"><p><?php //the_sub_field( 'what_description' ); ?></p>

@thoronas
Copy link
Author

the_sub_field( 'what_image' ) needs to be get_sub_field( 'what_image' )

Edit: Also what Joey said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment