我正在运行下面的查询,该查询从$ _SESSION中的数组中获取ID数组。
<?php
$ids = array();
foreach($_SESSION['collection'] as $el)
$ids[] = $el['ExerciseID'];
// START OF THE QUERY USING THE EXERCISE ID'S FOR DISPLAYING IN THE COLLECTION
$the_query = new WP_Query(array('post__in' => $ids, 'post_type' => 'exercise','posts_per_page' =>'4000')); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-sm-2">
<div class="thumbnail">
<?php the_post_thumbnail('collection_thumb'); ?>
<div class="caption">
<h5>
<?php the_title(); ?>
</h5>
</div>
</div>
</div>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
<?php endif; ?>
只要数组中有某些东西,它就会完美地工作,但是当$ _SESSION为空并且因此数组为空时它会返回来自type =&gt;的所有帖子。行使。
非常感谢提前。