WordPress.org

Ready to get started?Download WordPress

Forums

Remove single post from query (3 posts)

  1. cjhmdm
    Member
    Posted 4 years ago #

    Hello, I have 2 queries on my single post page (single.php). My first query shows the full post for the article clicked, the second query shows the 3 latest posts in excerpt format, which happens to include the actual post being displayed.

    I'm using arras theme, and the double query is required, what I'm wondering is, is there a way to show the latest 3 posts in query 2 except for the full post being shown on that page?

    Since I suck at explaining, here's an example:

    mydomain/posts/newest
    mydomain/posts/2nd_newest
    mydomain/posts/3rd_newest
    mydomain/posts/4th_newest

    When mydomain/posts/newest is viewed, query 2 shows 2nd_newest, 3rd_newest and 4th_newest

    When mydomain/posts/2nd_newest is viewed, query 2 shows newest, 3rd_newest and 4th_newest

    When mydomain/posts/3rd_newest is viewed, query 2 shows newest, 2nd_newest and 4th_newest

    And so on and so forth.

    Is something like this possible? Thanks in advance for any enlightnement :)

  2. MichaelH
    Member
    Posted 4 years ago #

    Before you first loop, the loop that displays the single post, put

    $nodup=array();

    and inside that first loop put:

    $nodup[]=$post->ID;

    Then for your 2nd query something like:

    $args=array(
      'post__not_in' => array($nodup),
      'showposts'=>3,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
  3. Maxaud
    Member
    Posted 4 years ago #

    pretty useful code.

Topic Closed

This topic has been closed to new replies.

About this Topic