показывать только первый элемент цикла foreach типа acf - PullRequest
0 голосов
/ 30 октября 2018

я хочу показать только первый элемент типа "не все", которые имеют тип "payment-services". Как я могу это сделать? Надеюсь, кто-нибудь может мне помочь ...

<?php if( have_rows('events', 4127) ):
                    while ( have_rows('events', 4127) ) : the_row();

                        $types = get_sub_field('type');

                        foreach($types as $type) {
                            if ($type == "payment-services") { ?> 



                        <div class="item-<?php foreach($types as $type ): echo $type; echo ' ' ; endforeach; ?>">
                            <img class="events-images" src="<?php the_sub_field('image', 4127); ?>" alt="">
                            <h2 class="events-title"><?php the_sub_field('title', 4127); ?></h2>
                            <p class="events-date"><?php the_sub_field('date', 4127); ?></p>
                            <p class="events-location"><?php the_sub_field('location', 4127); ?></p>
                            <a class="events-url btn" href="<?php the_sub_field('url', 4127); ?>"><?php the_sub_field('url_text'); ?></a>
                        </div>

                         <?php break; ?>
                    <?php }

                         } 
                endwhile;
            endif; ?>
...