Support

Account

Home Forums ACF PRO Shortcode in the loop Reply To: Shortcode in the loop

  • Thank you @kiwicreative for the feedback. Here is more information so you may better see the issue. The below code works except for the contact form shortcode.

    First, this is for a Board of Directors page where each board member has their own contact form, i.e., shortcode.

    Second, the counter is used for a Bootstrap4 collapse area to hide each members contact form until it is opened upon being clicked.

    The below code is working… all but the contact forms (see near bottom of code). I suspect this is because there is no differentiation between each form because the code is using $short over and over again.

    Please let me know if you need more information. And thank you!

    
    <?php
    $count = 1;
    if( have_rows('directors_and_officers') ):
    
        while ( have_rows('directors_and_officers') ) : the_row();
        $member = $count++;
        echo "<div class='officer'><div class='photo'><img src='";
            the_sub_field('photo');
        echo "' width='300' height='300' alt='Photo of ";
            the_sub_field('name');
        echo "'><h3>";
            the_sub_field('name');
        echo "</h3><h2>";
            the_sub_field('title');
        echo "</h2><p>";
            the_sub_field('phone');
        echo "</p></div><div class='bio'>";
            the_sub_field('biography');
        echo "<button class='btn btn-primary' type='button' data-toggle='collapse' data-target='#collapse-";
        echo $member;
        echo "' aria-expanded='false' aria-controls='collapse-";
        echo $member;
        echo "'>Contact ";
        the_sub_field('name');
        echo "</button>
            <div class='collapse' id='collapse-";
        echo $member;
        echo "'>
            <div class='card card-body'>";
            $contactUs = get_field( "contact_form_shortcode" );
            $short = $contactUs;
        echo do_shortcode($short);
        echo "</div></div></div></div>";
    
        endwhile;
    
    else :
        // no rows found
    endif;
    ?>
    </div><!-- #officers -->