• Resolved greencode

    (@greencode)


    I have the following in my single.php file:

    query_posts(array('showposts'=> 4,'cat' => 5,'post__not_in' => array('current-post-id-here')));

    but what I’m wanting to do is to get the current post’s ID and then have that entered into where I’ve added “current-post-id-here” in the above code. After that I am listing the latest 4 posts underneath the main post content.

    I’d really appreciate any help with this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    normally (if there is no disturbance of the query before this) you can get the current post ID:

    query_posts(array('showposts'=> 4,'cat' => 5,'post__not_in' => array($post->ID)));

    if this is in a function, add global $post; before your line.

    Thread Starter greencode

    (@greencode)

    Thanks so much for this – that’s spot on and works a treat!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get current post ID and exclude’ is closed to new replies.