Support

Account

Home Forums Add-ons Repeater Field ACF get title from image

Helping

ACF get title from image

  • I like to show the title of the image but the only output i get is a character h. The image is visible and that piece of code works. What is going wrong?

    <?php while ( have_posts() ) : the_post(); ?>
    <?php if( get_field('projectafbeelding') ): ?>
    <?php while( has_sub_field('projectafbeelding') ): 
    $image = get_sub_field('afbeelding');
    $title = $image['title'];
    ?>
    <li style="background-image: url('<?php echo $image;?>');">
    <?php echo $title;?>
    </li>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php endwhile; ?>
  • You will need to set the return value of the image field to ‘object’, currently it looks set to ‘URL’.

    Then you can do something like this:

    <?php while ( have_posts() ) : the_post(); ?>
      <?php if( get_field('projectafbeelding') ): ?>
       <?php while( has_sub_field('projectafbeelding') ): 
        $image = get_sub_field('afbeelding');
       ?>
       <li style="background-image: url('<?php echo $image['url'];?>');">
        <?php echo $image['title'];?>
       </li>
      <?php endwhile; ?>
    <?php endif; ?>
    <?php endwhile; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF get title from image’ is closed to new replies.