• Hi, so to explain the problem in simple:

    I’m Displaying my post, then later on I am rewinding the loop and querying the posts to display related posts from the same category. The only problem is that the current post that this is on is being display in the related posts, how can i exclude it from my query?

    Many Thanks in advance i really appreciated it if anybody can help somehow.

Viewing 4 replies - 1 through 4 (of 4 total)
  • In your rewind loop for $query_posts use the offset parameter, like this:

    $query_posts('offset=1');

    See the Codex page for more information on how to use $query_posts

    Thread Starter xdesi

    (@xdesi)

    Hi Trisha Thanks for the reply,

    If i’m right then offset=1 excludes the most recent post from the query, how could i change this so it excludes the current post it’s on.

    It only describes how to use offset=1 in the codex.

    For More Information. Lets say the Post is called Blah and is in Cat 10.
    OK so it displays everything about this post called Blah, and then later on i have a rewind posts to show some related posts, so inside the query i want to show the titles of posts from cat=10 (which i can do fine), however i do not want to show the title of Blah again, but it’s currently doing this i need to exclude it from the query.

    Again many thanks.

    I’m trying to figure this out, too. It has something to do with using
    the_ID()

    but, I’m not sure how.

    Here’s the code I’m using:

    <?php $current_cat=get_the_category();
    $current_category = $current_cat[0]->cat_name; ?>
    <?php $query= 'category_name=' . $current_category. '&orderby=date&showposts=5'; // concatenate the query ?>
    <?php query_posts($query); // run the query ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
    <?php endwhile;?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to Exclude Current Post from Query?’ is closed to new replies.