'Wordpress : ACF image not showing

i try to display image but with Basic display (Object) but no showing

<?php 

$image = get_field('image');

if( !empty($image) ): ?>

    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />

<?php endif; ?>


Solution 1:[1]

From the ACF docs: http://www.advancedcustomfields.com/resources/image/

<?php 

$image = get_field('image');

if( !empty($image) ): 

	// vars
	$url = $image['url'];
	$title = $image['title'];
	$alt = $image['alt'];
	$caption = $image['caption'];

	// thumbnail
	$size = 'thumbnail';
	$thumb = $image['sizes'][ $size ];
	$width = $image['sizes'][ $size . '-width' ];
	$height = $image['sizes'][ $size . '-height' ];

	if( $caption ): ?>

		<div class="wp-caption">

	<?php endif; ?>

	<a href="<?php echo $url; ?>" title="<?php echo $title; ?>">

		<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />

	</a>

	<?php if( $caption ): ?>

			<p class="wp-caption-text"><?php echo $caption; ?></p>

		</div>

	<?php endif; ?>

<?php endif; ?>

Using Object with the image field is more powerful, as it provides access to additional data, but requires a bit more work.

You may want to change the ACF field type to Image URL, which will return just the URL of the image, and can be inserted directly into your code

Hope this helps

D

Solution 2:[2]

It depends on what you set as the return value

enter image description here

  • Image Array will output as you have done
  • Image URL will return a string of the URL
  • Image ID will return the ID, so you'd need additional lookups to get the URL

If you are using this outside a loop then you must pass the post ID get_field('image', $post_id);

If it is a taxonomy term and not a post/page then you must pass a prefix get_field('image', 'category_' . $cat_id );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mr_DW_Brighton
Solution 2 C?????N????