WP_Query breaking the loop in a nested loop

Question

I’m not able to figure out the solution for the following code. When I remove the query section, the location loops but with the code, only one result of location (parent loop) is displayed.

    if (have_rows("locations")):
    while (have_rows('locations')): the_row();
        ?>
    <section class="content container pt-0">
    <div class="contain-container">
        <div class="row">
            <div class="col-xs-12 col-lg-12" data-aos="fade-up">
                <?php

                <div class="displayaddress">
                    <div class="col-lg-6 col-sm-12">
                        <div class="p-lg max-conten">
                            <?php echo get_sub_field("content_text"); ?> </div>
                        <?php
        $link = get_sub_field('content_button_link');
        if ($link) {
            $link_url = get_sub_field('content_button_link');
        } else {
            $link_url = "#";
        }?>
                        <div class="info">
                            <p class="st3">Address</p>
                            <p class="p-md"><?php echo get_sub_field('address'); ?></p>
                            <a href="<?php $link_url;?>" class="gold-link grey">GET DIRECTIONS →</a>
                        </div>
                        <div class="info">
                            <p class="st3">Phone</p>
                            <p class="p-lg"><?php echo get_sub_field('phone'); ?></p>
                        </div>
                        <div class="info">
                            <p class="st3">Opening Hours</p>
                            <p class="p-lg"><?php echo get_sub_field('opening_hours'); ?></p>
                        </div>
                    </div>
                    <div class="col-lg-6 text-right col-sm-12">
                        <?php echo get_sub_field('map_iframe'); ?>
                    </div>
                </div>

                <?php $featured_posts = get_sub_field('designs_on_display');
        if ($featured_posts) {
            ?>
                <p class="mid-gold st2 bold container dod-title">Designs on Display</p>
                <div class="designondisplay">
                    <?php foreach ($featured_posts as $featured_post) {
                $args = array(
                    'p' => $featured_post,
                    'post_type' => 'any',
                    'post_parent' => 0,
                );
                $query = new WP_Query($args);
                while ($query->have_posts()): $query->the_post();
                    $termsBath = get_the_terms($post->ID, 'bathrooms');
                    $termsBath = array_shift($termsBath);
                    $storey = get_the_terms($post->ID, 'storeys');
                    $storey = array_shift($storey);
                    $bedroom = get_the_terms($post->ID, 'bedrooms');
                    $bedroom = array_shift($bedroom);
                    ?>
                    <div class="col-sm-12 col-md-6 col-lg-3 p-0" data-aos="fade-up">
                        <div class="project-grid ">
                            <a href=" <?php echo get_permalink(); ?>">
                                <?php
            while (have_rows('home_images')): the_row();?>

                                <?php
                $image = $image_url[0];?>
                                <img src="<?php echo get_sub_field('image')['url'] ?>"
                                    alt="<?php echo get_the_title(); ?>" />
                                <?php

                        break;
                    endwhile;
                    ?>

                                <div class="projectMeta">
                                        <div class="projectIcons">
                                        <h5 class="p-lg gold-9b"><?php echo get_the_title(); ?>
                                        </h5>
                                        <?php
           $bedroom = $bedroom->name;
                    echo '<span class="icon-number"><img class="bedIcon" src="' . get_template_directory_uri() . '/images/Bed@2x.svg" />';
                    echo str_replace("Bedrooms", "", $bedroom) . '</span>';

                    if (!empty($termsBath)) {?><span class="icon-number"><?php
            echo '<img class="bathIcon" src="' . get_template_directory_uri() . '/images/Bathtub@2x.svg" />';

                        $bathroom = $termsBath->name;
                        echo str_replace("Bathroom", "", str_replace("Bathrooms", "", $bathroom));
                        echo "</span>";
                    }
                    ?>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>
                    <?php endwhile;}
        }
        ?>
                </div>
            </div>

        </div>
    </div>
</section>
<?php

    endwhile;
endif;
?>
0
Miraj Aryal 2 months 0 Answers 17 views 0

Leave an answer