WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding specific posts from a custom WP_Query() (3 posts)

  1. stevechatterton
    Member
    Posted 4 years ago #

    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.

  2. MichaelH
    Member
    Posted 4 years ago #

    Did you try the post__not_in argument?

    See query_posts().

  3. stevechatterton
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic