简体   繁体   中英

Excluding a certain post from Wordpress loop

I have a homepage with four displayed posts and one that is emphasized.

The one that is emphasized is not a problem, it's a large post whose details i collect using special loop.

But for those four posts (that have pagination), I just can't seem to exclude that emphasized one.

For example, if emphasized post has ID of 8, this should do the trick:

$args=array(
        'paged' => $paged,
        'posts_per_page' => 4,
        array('post__not_in' => array(8))
    );

    query_posts($args);

    while ( have_posts() ) : the_post();
        echo '<li>';
        the_title(); 
        echo "<span> ".$post->ID."</span>";
        echo '</li>';
    endwhile;

But for some reason it's not filtering anything, always displays all the posts.

Any ideas why this is happening?

Why is the post__not_in in another array? I would recommend putting it on the same level:

$args=array(
        'paged' => $paged,
        'posts_per_page' => 4,
        'post__not_in' => array(8)
);

If that doesn't help, I would recommend checking approaches mentioned here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM