3

我试图让 WordPress 不显示某些帖子,但它似乎仍然显示我告诉它不要的帖子。我目前有这个代码:

<?php
    if (have_posts()) : while (have_posts()) : the_post(); 
    if (in_array($post->ID, $_SESSION['save_array_posts'])) continue;
?>
<div class="yl_bg_post main_content videos">
    <h2 class="title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <?php the_content('<p class="more">More></p>'); ?>
</div>
<?php endwhile; endif; ?>

我试图让 WordPress 不显示存储在$_SESSION['save_array_posts']. 值如下:

array(5) { [0]=> int(190) [1]=> int(199) [2]=> int(63) [3]=> int(66) [4]=> int(68) }

WordPress 似乎在循环并仍然显示它们,我不太清楚为什么。

4

1 回答 1

2

不知道为什么你有这个问题,但你可以尝试像这样在查询中排除帖子,看看是否能解决你的问题:

$myPosts = new WP_Query(array('post__not_in' => $_SESSION['save_array_posts']));

while ($myPosts->have_posts()) : $myPosts->the_post(); ?>
于 2013-05-03T19:58:57.350 回答