仅通过特定ID循环

时间:2016-04-13 08:04:03

标签: php wordpress loops

我正在通过自定义帖子类型运行循环,如下所示:

<?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; ?>

这将返回所有帖子,但我怎样才能获得具有特定ID的帖子?应该有4个帖子显示ID 149,151,161,163。

1 个答案:

答案 0 :(得分:2)

尝试使用

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

获取具有特定ID的帖子。

相关问题