Home Forums General Issues Nested Groups Not Finding Img Alt Text


Nested Groups Not Finding Img Alt Text

  • Hello! Thanks in advance for any help.

    I have two nested groups I’m trying to iterate over. This is supposed to be a grid of logos, each with a link to the company website. I’m loading my images as image arrays, and loading the alt text for each logo is essential for this project. I keep getting

    Warning: illegal string offset 'alt'

    Here’s my code:

    <?php $partners = get_field('partners_logos'); ?>
            <?php $sites = get_field('partners_links'); ?>
              <?php foreach(array_combine($partners, $sites) as $logo => $site) {
                if (!empty($logo)): ?>
                  <?php if ( $site ): ?>
                    <a href="<?php echo esc_url( $site ); ?>">
                      <img src="<?php echo esc_url($logo['url']); ?>" alt="<?php echo esc_url($logo['alt']); ?>" />
                  <?php endif; ?>
                <?php endif;
               } ?>
  • I might be wrong, but I think your issues is with using array_combine()

    Try using array_merge()

  • Unfortunately it’s still giving me the same error, just now iterated four times for my four logos.

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

You must be logged in to reply to this topic.