0

I have a shortcode that lists CPTs and works great everywhere but if I use the shortcode in an ACF repeater the reapeater stops repeating right after the shortcode. I tried reseting postdata in various way in the shortcode, but nothing has worked yet. Appreciate any guidance.

<section id="consumer_resources-list" class="padding-top-1">
    <div class="container">
        <ul class="accordion margin-bottom-0" data-accordion role="tablist" data-allow-all-closed="true">
            <?php while (have_rows('field_61134ad5cf0b3')): the_row(); ?>
              <li class="accordion-item" data-accordion-item >
                <a href="#" class="accordion-title h5 margin-0"><?= get_sub_field('field_61134b21cf0b4') ?></a>
                <div class="accordion-content margin-horizontal-1" data-tab-content>
                    <div class="inner-content">
                        <?= get_sub_field('field_61134b4bcf0b5') ?>
                    </div>
                </div>
              </li>
            <?php   endwhile;  ?>
        </ul>
    </div>
</section>

This is the shortcode in function.php

add_shortcode( 'list_webinars', 'getting_webinars' );

function getting_webinars($atts, $content = null) {
ob_start();

    extract(shortcode_atts(array(
        'language' => 'spanish',
        'webinarcat' => '',
    ), $atts));

    $futureposts = new WP_Query(array(
        'post_type'         => 'webinar',
        'posts_per_page'    => -1,
        //'tax_query' => array(
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'webinar_categories',
                'field'    => 'slug',
                'terms' =>$webinarcat,
            ),
            array(
                'taxonomy' => 'webinar_categories',
                'field'    => 'slug',
                'terms' =>$language,
            )
        ),
        'meta_key'          => 'webinar_date',
        'meta_value'        => date('Ymd', strtotime('-1 day')),
        'orderby'           => 'meta_value',
        'order'             => 'ASC',
        'meta_compare'      => '>',
    ));

    if ($futureposts-> have_posts()){
        
        $retour='<ul class="events-list" style="list-style:none;">';

        while ( $futureposts->have_posts() ) : $futureposts->the_post();
                
$retour .= '<li class="  ' . implode (' ', get_post_class( 'individualWebinar' ) ). '">';
$retour.=    '<span class="event-title-webinar"><a href="' . get_field('field_627d909680aac') . '" target="_blank"> ' . ucfirst($language) . '-';           
$dateTime = strtotime(get_field('field_627d84f3648f2'));
$retour .= date('l, F j, Y', $dateTime) . ' ';
$retour .= '@ '. get_field( "field_627eeb2af6475" ) . ' MST - Register Here >></a></span> </li> ';      
        endwhile; 
        $retour .= '</ul>';         
        return $retour;

    } else { return '<strong>No upcoming events are currently on the calendar.</strong>'; }
wp_reset_postdata();
return ob_get_clean();
} 

1 Answer 1

0

Change the end to proper syntax,

        endwhile; 
        $retour .= '</ul>';         
        wp_reset_postdata();    
        return $retour;
        
    } else { return '<strong>No upcoming events are currently on the calendar.</strong>'; }

return ob_get_clean();  

} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.