通过WordPress循环按ID循环CPT

我试图使用WP循环仅循环自定义帖子类型, 但仅显示我通过ID给出的类型。
这是我现在的” 正常” 循环:

< ?php $args = array('post_type' => 'referenties', 'posts_per_page' => 5, 'order' => 'DESC', ); ?> < ?php $number = 0; query_posts($args); if(have_posts()): ?> < !-- /Carousel script --> < div class="container"> < div class="carousel-loop"> < div id="myCarousel" class="carousel slide"> < ol class="carousel-indicators"> < ?php while(have_posts()): the_post(); ?> < li data-target="#myCarousel" data-slide-to="< ?php echo $number++; ?> "> < /li> < ?php endwhile; ?> < /ol> < div class="controle-buttons"> < a class="carousel-control left" href="http://www.srcmini.com/#myCarousel" data-slide="prev"> < i class="fa fa-chevron-circle-left"> < /i> < /a> < a class="carousel-control right" href="http://www.srcmini.com/#myCarousel" data-slide="next"> < i class="fa fa-chevron-circle-right"> < /i> < /a> < /div> < !-- Carousel items --> < div class="carousel-inner"> < ?php while(have_posts()): the_post(); ?> < !-- Carousel nav --> < div class="item"> < div class="col-sm-2"> < ?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?> < ?php the_post_thumbnail(array(150, 150)); // Declare pixel size you need inside the array ?> < /div> < div class="col-sm-4"> < h4> < ?php the_title(); ?> < /h4> < ?php $bedrijf = get_field('naam_bedrijf'); ?> < ?php $feest = get_field('feest'); ?> < ?php $link = get_field('mylink'); ?> < ?php echo '< p> Bedrijfsnaam: ' . $bedrijf . '< /p> '; ?> < ?php $post_object = get_field('mylink'); if( $post_object ): $post = $post_object; setup_postdata( $post ); ?> < p> Feest type: < a style="color:#ff6600" href="http://www.srcmini.com/< ?php the_permalink(); ?>"> < ?php the_title(); ?> < /a> < /p> < ?php endif; ?> < /div> < ?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> < div class="col-sm-4 col-sm-offset-1"> < h4> Opmerking< /h4> < p> < ?php echo custom_field_excerpt_longer(); ?> < /p> < ?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> < ?php echo '< p> ' . wp_review_show_total() . '< /p> '; ?> < /div> < ?php endif; ?> < /div> < ?php endwhile; ?>

【通过WordPress循环按ID循环CPT】但我只想显示帖子ID:2706、2462、2514、2511和2505。
循环显示在轮播中, 效果很好。但我只希望显示ID, 而不是添加所有帖子。
#1使用这样的东西:
< ?php $args = array( 'post_type' => 'referenties', 'post__in'=> array(2706, 2462, 2514, 2511, 2505), 'order'=> 'DESC', ); $the_query = new WP_Query($args); // The Loop if ( $the_query-> have_posts() ) { while ( $the_query-> have_posts() ) { $the_query-> the_post(); //post content output goes here} // Restore original Post Data wp_reset_postdata(); } else { // no posts found }

post__in()参数使用具有所需帖子ID的数组进行检索。
不要将query_posts用于自定义查询。太多会出错。
希望这可以帮助 :)

    推荐阅读