Support

Account

Home Forums ACF PRO Error display field image

Solving

Error display field image

    • kraudio

    • October 7, 2014 at 7:13 am

    Hello, I’m doing a loop to display the posts with an image (ac_imagem_destaque). However, shows that when I load the page:

    <img src="Array" class="thumb_285_350">

    My code ACF:

    if( function_exists('register_field_group') ):
    
    register_field_group(array (
    	'key' => 'group_542dbe51e7081',
    	'title' => 'Imagem',
    	'fields' => array (
    		array (
    			'key' => 'field_542b213539ac3',
    			'label' => 'Imagem para o destaque',
    			'name' => 'ac_imagem_destaque',
    			'prefix' => '',
    			'type' => 'image',
    			'instructions' => 'Obs.: Destaque1a, Destaque1c, DestaqueGarotos e DestaqueTravestis tem de largura 285px e de altura 350px.
    O Destaqueesquerda	tem de largura 243px e de altura 350px',
    			'required' => 1,
    			'conditional_logic' => 0,
    			'preview_size' => 'acfimage',
    			'library' => 'uploadedTo',
    			'return_format' => 'url',
    		),
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'post',
    			),
    		),
    	),
    	'menu_order' => 0,
    	'position' => 'normal',
    	'style' => 'default',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => array (
    	),
    ));
    
    endif;

    My page code of the loop:

    <?php query_posts('posts_per_page=99&tag=destaque1a&showposts=99'); if (have_posts()) : while (have_posts()) : the_post(); ?>
    									<div class="float_list_capa">			
    
    										<?php if( get_field('ac_imagem_destaque') ): ?>
    											<img src=<?php the_field('ac_imagem_destaque'); ?> class=thumb_285_350 >
    											<?php //print_r( get_field('ac_imagem_destaque') ); die; ?>
    										<?php endif; ?>
    
    										<div class=list_capa_esquerda_title><a href=<?php the_permalink(); ?> ><?php the_title(); ?></a></div>
    									</div>
    • kraudio

    • October 7, 2014 at 7:46 am

    checking values

    <?php if( get_field('ac_imagem_destaque') ): ?>
    <?php print_r( get_field('ac_imagem_destaque') ); die; ?>
    <?php endif; ?>

    returning

    (
        [0] => Array
            (
                [ID] => 2062
                [id] => 2062
                [alt] => 
                [title] => destaque1a1
                [caption] => 
                [description] => 
                [mime_type] => image/jpeg
                [type] => image
                [url] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1.jpg
                [width] => 285
                [height] => 350
                [sizes] => Array
                    (
                        [thumbnail] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1-150x150.jpg
                        [thumbnail-width] => 150
                        [thumbnail-height] => 150
                        [medium] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1-244x300.jpg
                        [medium-width] => 244
                        [medium-height] => 300
                        [large] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1.jpg
                        [large-width] => 285
                        [large-height] => 350
                        [post-thumbnail] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1.jpg
                        [post-thumbnail-width] => 285
                        [post-thumbnail-height] => 350
                        [capa_thumb] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1.jpg
                        [capa_thumb-width] => 285
                        [capa_thumb-height] => 350
                        [capa_esquerda_thumb] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1-243x298.jpg
                        [capa_esquerda_thumb-width] => 243
                        [capa_esquerda_thumb-height] => 298
                        [galeria_thumb] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1.jpg
                        [galeria_thumb-width] => 285
                        [galeria_thumb-height] => 350
                        [acfimage] => http://acrio.com.br/wp-content/uploads/2014/10/destaque1a1.jpg
                        [acfimage-width] => 285
                        [acfimage-height] => 350
                    )
    
            )
    
    )
  • By default images are returned as an array.

    You need to either change this to URL, or else you can pull the details from the array to get the URL, eg:

    
    <?php
    $image = get_field('ac_imagem_destaque');
    if( $image): 
       $alt = $image['alt'];		
       $thumb = $image['url'];
       $width = $image['width'];
       $height = $image['height'];
       ?>
    
       <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" class="thumb_285_350" />
    										
    <?php endif; ?>
    

    You can read more here – http://www.advancedcustomfields.com/resources/image/

    • kraudio

    • October 8, 2014 at 12:43 am

    Good morning, thanks for the help

    But not yet worked out, looks like the generated html
    <img src = "" alt = "" class = "thumb_285_350" height = "" width = "">

    What can it be?

  • That’s really wierd, do you have an image selected in the backend?

    Can you try doing a printr on the field again inside that if statement?

    • Elliot

    • October 8, 2014 at 5:41 pm

    Hi @kraudio

    It looks like the returned value is wrapped in another array. Your var_dump shows this in the first line: [0] => Array

    Can you test the unformatted value:

    <?php 
    
    echo '<pre>';
    	print_r( get_field('ac_imagem_destaque', false, false) );
    echo '</pre>';
    ?>
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

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.