Support » Fixing WordPress » excluding page ID's using 'post__not_in'

  • I am trying to remove specific page ID’s from a listing using the following code:

    <?php query_posts( ‘post__not_in(264)&post_type=page&posts_per_page=100&orderby=menu_order&order=asc’ ) ; ?>

    The ‘post__not_in’ function is not working…no doubt due to the fact that I am completely ignorant on the topic of PHP.

    Can someone please tell me what’s wrong with my code snippet?

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php query_posts( ‘post__not_in=array(264)&post_type=page&posts_per_page=100&orderby=menu_order&order=asc’ ) ; ?>

    Thanks for the reply.

    When I use that code I get these error messages:

    Warning: array_map() [function.array-map]: Argument #2 should be an array in /nfs/c08/h03/mnt/122148/domains/ on line 2104

    Warning: implode() [function.implode]: Invalid arguments passed in /nfs/c08/h03/mnt/122148/domains/ on line 2104

    Any idea what’s going on?


    I’ve just checked the post__not_in function and it appears to accept post ids without single quotation marks, so that’s not the issue.

    When I put in:


    it excluds the posts. But when I replace that with:


    it doesn’t work, even though $mypostids printed is 555,553,152,46 exactly.



    Forum Moderator

    it might be the best if you rewrite the line:

    $args = array(
    'post__not_in' => array(264, 234),
    'post_type' => 'page',
    'posts_per_page' => 100,
    'orderby' => 'menu_order',
    'order' => ASC
    query_posts( $args ); ?>

    Thanks for this help.. I’ve been trying for a day to get a 4-loop front page to work. The code I used for my queries looks like this

    <?php $lead_post_query = new WP_Query( array ('post__not_in'=> $do_not_duplicate, 'showposts'=>'1'));
    	while ($lead_post_query->have_posts()) : $lead_post_query->the_post();
    	 array_push($do_not_duplicate, $post->ID) ?>

    The key is to make a single array called $do_not_duplicate with already published posts.

    Then use post__not_in to filter your nest query.

    Then amend new IDs to $do_not_duplicate with array_push.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘excluding page ID's using 'post__not_in'’ is closed to new replies.