Slavisa Perisic
Slavisa Perisic

Reputation: 1110

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?

Upvotes: 0

Views: 1979

Answers (1)

petr
petr

Reputation: 2586

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.

Upvotes: 3

Related Questions