• I am using wp_Query to get the first 10 newest posts.

    However, occasionally I need to exclude a single post from the list.

    I’m not seeing in the codex how to exclude a post by ID.

Viewing 2 replies - 1 through 2 (of 2 total)
  • There is. in the array of parameters you pass to the WP_Query class, use post__not_in parameter, with an array of id’s you want to skip. (Note the double underscore between ‘post’ and ‘not’)

    Example:

    $args = array(
        'post__not_in' => array(1,2,3)
    );
    $query = new WP_Query($args);

    This would get posts that do not have the id’s 1, 2, or 3

    Thread Starter Dave Navarro, Jr.

    (@dnavarrojr)

    Worked perfectly, thank you so much!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is it possible to exclude a single post?’ is closed to new replies.