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 に答える