Content is getting displayed endlessly when trying to loop

I would like to loop through a query within a query.

This should actually make it:

Read More
<div class="container inner-cont">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="row">
            <div class="col-md-8 column">
                <?php the_content(); ?>
            </div>
            <div class="col-md-4">

                <!-- START -->
                <?php 
                    query_posts(array( 
                        'post_type' => 'mitarbeiter',
                        'showposts' => 10 
                    ) );

                    // Get the members 
                    while (have_posts()) : the_post();
                        if (in_array($title, get_field('kompetenzen'))) :
                            // Display the image
                            $image = get_field('portraitfoto');
                            if (!empty($image)): ?>
                                <img class="sidebar-img" src="<?= $image['url']; ?>" alt="<?= $image['alt']; ?>" /><br />
                            <?php endif; ?>

                            <h2><?php the_title(); ?></h2>
                            <?= the_field('funktion'); ?><br>
                            <?= the_field('telefon'); ?><br>
                            <?= the_field('email'); ?><br>
                        <?php endif; ?>
                    <?php endwhile; ?>
                <!-- END -->

            </div>
        </div>


        <?php endwhile; else: ?>
    <?php endif; ?>
</div>

The problem that I have is, the loop which you find between <!-- START --> and <!--END --> is running endlessly! The same content gets displayed over and over again. Why is this happening and how can I fix it?

Related posts

1 comment

  1. After end of second query you must reset query.

    <?php wp_reset_query(); ?>
    

    This code will be reset query.

Comments are closed.