Support

Account

Home Forums Front-end Issues issues displaying an image with the_field()

Solving

issues displaying an image with the_field()

  • Here it is..

    When a user submit a post with a title, a price and a picture. I manage to only display the title and the price but not the image on the Web page using :

    <?php 					
    
    $loop = new WP_Query(array(
      'post_type' => 'boat',
      'orderby' => 'date',
      'posts_per_page' => 6
    ));
    	
    while ( $loop->have_posts() ) : $loop->the_post(); 
    
    ?>
    
    <a href="<?php the_permalink() ?>" title="<?php the_field('title'); ?>"><img alt="<?php the_field('title'); ?>" src="<?php the_field('image'); ?>" width="155px" height="133px" /></a>
    
    <span><?php the_field('title') ?></span>		                   
    <span><?php the_field('price'); ?> $</span>
    			
    			
    <?php 
        endwhile;
        wp_reset_query(); 
    ?>

    All it does return for the image is the ID but not the link+id. I checked the option in ACF for this image field :

    ‘Specify the returned value on front end’ -> URL

    and i still only get the ID.

    Did i forgot anything ?

  • Hi,

    It should works.

    You can also choose Image Object radio box then get the value with get_field_object('image'). It retrives an array with almost anything you need. For example you can get image url like below:

    $fields = get_field_object('image');
    
    <img src="<?php echo $fields['value']['url']; ?>" alt="<?php echo $fields['value']['alt']; ?>" />

    For seeing the whole array use <pre><?php print_r(get_field_object('image'))?></pre> somewhere in the loop.

    I hope that helps,

  • I have this same problem, i think something is wrong with the value, because the array holds type=text even though is saved as image.

    <div class=”users”>
    <?php
    $users = get_users(“fields=all_with_meta”);
    foreach ($users as $user) {
    echo ‘<h2>’ . $user->fighter_name . ‘</h2>’;
    echo ‘<p>’ . $user->perfects_done . ‘</p>’;
    echo print_r( get_field_object(‘fighter_pic’) );
    }
    ?>
    </div>

    returns

    Array ( [key] => field_fighter_pic [label] => [name] => fighter_pic [type] => text [order_no] => 1 [instructions] => [required] => 0 [id] => acf-field-fighter_pic [class] => text [conditional_logic] => Array ( [status] => 0 [allorany] => all [rules] => 0 ) [default_value] => [formatting] => html [maxlength] => [placeholder] => [prepend] => [append] => [value] => ) 1

  • Hi @pouki

    Your issue is not with the image field, it is with loading data form a user. Please read the docs here:
    http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-user/

    Thanks
    E

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

The topic ‘issues displaying an image with the_field()’ is closed to new replies.