your problem is that in the first loop you overwrite $do_not_duplicate
for each post in the loop so at the end you only have the id of the last post.
if you change $do_not_duplicate into an array then you can add each post to the array:
//before the loop
$do_not_duplicate = array();
//in the loop
$do_not_duplicate[] = $post->ID;
then you can just use in in the second query :
<?php query_posts($query_string . '&cat=-15,-17, -5, -2&post_type=post&posts_per_page=9&post__not_in='.$do_not_duplicate); ?>
Related Posts:
- Custom loops, sticky posts, and pagination nightmare
- How to return results of a get_posts() in explicitly defined order
- Ensuring sticky posts are retrieved first (without using two queries)?
- Modify main WordPress loop with a parse_query filter
- Limiting query_posts to 1, regardless of sticky post?
- How to make “sticky” pages (and query by them)
- How should I intercept the main query and inject custom join / order by / group by criteria
- Schedule Sticky Posts
- Dynamically excluding current page id
- How to order results by date and meta key?
- Static Front-Page Excerpts
- Is it possible to query_posts using post__in and then Loop through them in the ordered they were queried?
- query_posts() ALWAYS displays something?
- 3 Posts in Loop, Show Stickies First
- How to remove a plugin filter’s priority on specific loops (custom queries)?
- Exclude first post (sticky or not) from the loop using query_posts()
- Filter Loop by Custom Field Value
- Exclude current sticky post
- Modify loop but keep the original query, what am I doing wrong?
- When to use WordPress loop or Foreach loop?
- Post per page not working if no category specified
- Can’t get pagination to work for sticky posts only
- Sticky posts don’t show up first in custom loop
- Calling Posts from Specified Cat
- Most Effective Method? Exclude Category and Number of Posts Per Page
- How do I query based on the modified date?
- Script that gets the first tag of post and query all other posts with the same tag
- How to add an “or” instead of and “and” (&) in a WordPress query?
- Custom loop off by one post
- Modify main loop query for paged and meta key
- wordpress query_posts featured page always on top
- Create a Loop with Posts Ordered by Most Recent Comments
- query_posts and sub pages?
- The_content display a different content from a previous loop
- WordPress loop problem: Multiple loops, index.php and is_paged causing duplicate posts on next page
- Including post data in a sidebar occurring outside of and before the Loop
- how to query posts by category and tag?
- How to set posts per page using WP_Query()
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Apply styling only to first page sticky posts
- How to create an attachments archive with working pagination?
- how could I get the pagination as I want to when query posts using get_posts function
- Counter code for paginated category pages in wordpress
- Author List page: Exclude based on last post date
- Replace query_posts with pre_get_posts
- query_posts sort in multiple directions
- Filter query_posts by tag slug on “Tag Archive” page (when tag is 2 or more words)
- Warning: urlencode() expects parameter 1 to be string, array given in and not getting the preffered output
- Query for posts in 2 taxonomies
- Using database meta_values to calculate new post order using pre_get_posts or a ‘request’ hook
- exclude ids through post__not_in
- Exclude category from loop not working
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- Integrating post archive wtih another source and preserving date ordering
- Order posts using a custom array
- Show Only Posts Owned By Logged In User + my post
- Custom MySQL Query with logic
- Query last updated posts (posts updated in the last 24 hours)
- order posts by meta value on posts page
- Show a Category X’s custom post type on Category X archive page?
- trouble with query to fetch next and previous posts
- Some doubts about how the main query and the custom query works in this custom theme?
- Simple custom post query for all the posts or many of them not working
- Hook to return true when the_post() is used in a custom while loop
- Proper syntax to add boolean in array()
- using query_posts to pull posts out of a category in a while loop. Getting odd echo
- Echo a numerical value in query_posts
- why to use query_posts() in custom page?
- Query posts to get all but the most recent post
- Always using the same ARRAY on different querys
- Include current post into loop
- How to only publish posts with image in it
- How do I use pagination in WordPress?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Does WordPress run a post query when a page is invoked?
- Using functions.php to include code that’s processed inline
- Multiple posts/pages in one page?
- query_posts clarification needed
- Paginate pages with dynamic query
- Determine if ID is page or post and query the ID
- How to check a list or feed of all posts under a category and tag?
- How do I add a timezone offset to this query?
- Instead of 4 loops, how can I do it better?
- Need to add a space after meta value in query_posts in wordpress for zipcode search
- Tax query get first product with attribute value in pre_get_posts
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Ordering Posts By Meta Data
- Some doubts about how the main query and the custom query works in this custom theme?
- Ordering Posts by parent category, name ascending
- No duplicate tags by category
- why is pre_get_posts not working
- If meta_key has value = 6 | Change the wp_posts.post_date to current date
- Query posts based on parents attribute
- Adding Category Argument into an Array for WordPress Query
- Filtering posts by WORD in custom field
- Run second query on page based on author of the first query
- Why doesn’t this page query work?
- show custom post’s post in two different divs [duplicate]
- First post outside of loop, homepage only?