excluding page ID's using 'post__not_in' (6 posts)

  1. missionbombshell
    Posted 4 years ago #

    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?

  2. 123milliseconds
    Posted 4 years ago #

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

  3. missionbombshell
    Posted 4 years ago #

    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/missionbombshell.com/html/wp-includes/query.php on line 2104

    Warning: implode() [function.implode]: Invalid arguments passed in /nfs/c08/h03/mnt/122148/domains/missionbombshell.com/html/wp-includes/query.php on line 2104

    Any idea what's going on?

  4. 123milliseconds
    Posted 4 years ago #

    From http://wordpress.org/support/topic/how-to-extract-post-ids-from-an-array?replies=10

    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.

  5. alchymyth
    Forum Moderator
    Posted 4 years ago #

    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 ); ?>
  6. photocurio
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic