Pom Canys
Pom Canys

Reputation: 379

Loop only through specific IDs

I am running a loop through a custom post type which looks like this:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <!-- START MEMBER LOOP -->
    <?php 
        query_posts(array( 
            'post_type' => 'mitarbeiter',
        ) );

        // Get the members 
        while (have_posts()) : the_post();
            ?>                          
                <div class="col-md-6">
                    <div class="well">
                        <div class="row">
                            <div class="col-xs-5">
                                <?php 
                                // Display the image
                                $image = get_field('portraitfoto');
                                if (!empty($image)): ?>
                                    <img class="sidebar-img" src="<?= $image['url']; ?>" alt="<?= $image['alt']; ?>" /><br />
                                <?php endif; ?>
                            </div><!-- /.col-xs-5 -->
                            <div class="col-xs-7">
                                <h2><?php the_title(); ?></h2>
                                <p><?= the_field('funktion'); ?><br>
                                <?= the_field('abteilung'); ?><br>
                                <?= the_field('telefon'); ?><br>
                                <a href="mailto:<?= the_field('email'); ?>"><?= the_field('email'); ?></a></p>
                            </div><!-- /.col-xs-7 -->
                        </div><!-- /.row -->
                    </div><!-- /.well -->
                </div><!-- /.col-md-6 -->

        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
        <!-- END MEMBER LOOP -->
<?php endwhile; else: ?>
<?php endif; ?>

This returns all the posts but how can I get only posts with specific IDs? There should be 4 posts to show with the IDs 149, 151, 161, 163.

Upvotes: 0

Views: 184

Answers (1)

Nutshell
Nutshell

Reputation: 8537

Try using

query_posts( array('post__in' => array(149,151,161,163)) );

To get posts with specific IDs.

Upvotes: 2

Related Questions