WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Excluding specific posts from a custom WP_Query()

[Resolved] Excluding specific posts from a custom WP_Query()

  • stevechatterton
    Member

    @stevechatterton

    I’ve got a bit of a problem I’m trying to resolve on this page:
    http://www.thelitreview.com/

    It’s a site about books, and the site’s posts are exclusively split up between fiction, non-fiction & site news. I’m using a custom WP_Query function to keep the categories separate from each other. For example, this is how the fiction category looks under the hood:

    <?php $my_query1 = new WP_Query('category_name=fiction&showposts=7');
    while ($my_query1->have_posts()) : $my_query1->the_post();
    $do_not_duplicate1 = $post->ID; ?>

    Now I want to be able to specify certain posts to be excluded from front page display. I’ve tried modifying the parameters to something like this:

    $my_query1 = new WP_Query('category_name=fiction&showposts=7&p=-1,-3,-7');

    But the results have been disastrous. Does anyone know what I’m doing wrong? Better yet, does anyone know how to do it right? I’d really appreciate it if some kind soul could help point me in the right direction.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Did you try the post__not_in argument?

    See query_posts().

    stevechatterton
    Member

    @stevechatterton

    Thanks, MichaelH.

    I changed my statement to this:

    <?php

    $args=array(
    ‘cat’=>1,
    ‘caller_get_posts’=>7,
    ‘post__not_in’ => array(1111,1115)
    );

    $my_query1 = new WP_Query($args);
    while ($my_query1->have_posts()) : $my_query1->the_post();
    $do_not_duplicate1 = $post->ID; ?>

    And it does exactly what I need.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Excluding specific posts from a custom WP_Query()’ is closed to new replies.