Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix fixing invalid argument supplied for foreach() problem

Discussion in 'Misc WordPress Requests' started by jordmiguel, Nov 2, 2017.

  1. jordmiguel

    Guest

    fixing invalid argument supplied for foreach() problem, by jordmiguel

    I’ve noticed that the div image-16-8 from my hero.php file is not being displayed.

    When I inspect element I get Invalid argument supplied for foreach() in

    Here is the code:

    <?php

    function tbhHeroShortcode($atts)
    {

    $values = shortcode_atts(array(
    'images' => '',
    'first-line' => '',
    'second-line' => '',
    'video' => '',
    'link' => '',
    ), $atts);
    ob_start();
    ?>
    <div class="hero">
    <?
    $images = decode_shortcode_data($values['images']);
    if ($images): ?>
    <ul data-simple-slider>
    <?php foreach ($images as $image): ?>
    <li>
    <div class="image-16-8" style="background-image: url(<?= $image->url; ?>); "></div>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    <div class="hero-content">
    <div class="hero-content-first-line">
    <h1 class="header"><?= decode_shortcode_data($values['first-line']) ?></h1>

    </div>
    <h1 class="italic-header"><?= decode_shortcode_data($values['second-line']) ?></h1>

    <div class="hero-content-cta">
    <a class="hollow-button" href="<?= decode_shortcode_data($values['link']) ?>">Learn More</a>

    </div>

    </div>

    <?php if (count($images) > 1): ?>
    <div class="hero-controls">
    <i class="fa fa-chevron-left hero-controls__left" aria-hidden="true"></i>
    <i class="fa fa-chevron-right hero-controls__right" aria-hidden="true"></i>
    </div>
    <?php endif; ?>
    </div>
    <?php
    $component = ob_get_contents();
    ob_end_clean();
    return $component;
    }

    add_shortcode('tbhHero', 'tbhHeroShortcode');

    I have a feeling $images is not a variable and can’t be looped through.

    fixing invalid argument supplied for foreach() problem
     
    #1

Share This Page

Web Hosting