You are adding post IDs to $do_not_duplicate, but you are missing the other half of the process- excluding those post IDs from subsequent queries. You can do that by setting post__not_in with the array of IDs you don’t want returned.
$args = array(
'posts_per_page' => 1,
'paged' => $page,
'cat' => 2,
'post__not_in' => $do_not_duplicate,
);
Related Posts:
- Inject post (from specific category) between posts in Loop
- Wp Query : Order by distance lat,lon
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Query multiple custom post types in single loop
- Build a content and excerpt grid loop with paging and options for # of posts
- Looking to exclude blog posts from category Previous/Next buttons
- Alter secondary loop to exclude posts from current page category
- Search widget breaks when using multiple loops?
- Use template for posts with a particular category grandparent
- Count number of published posts by type
- Custom Loop through category menu to include sub categories
- How to exclude specific category from the get_the_category(); array
- Get taxonomy terms only of the WP_Query current posts
- How to get to a specific position in wp_query?
- Get category name from custom loop and echo it once
- Hide post if matches current month and year
- Using foreach loop breaks
- Display post category in foreach loop with category link
- Filter Select results based on selection
- Why WP_Query(‘showposts=5’) shows only 1 post?
- how do I get a specific post from a post with a subcategory in WP
- How can I add extra word in permalink when someone click download button?
- Alert Bar section within WP loop is displaying even though there are no posts
- remove post that has no content
- Display category name only once inside loop
- How to show only subcategories in parent category not parent category?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- List authors with the last post title and order by last post date
- Redirect to another page using contact form 7? [closed]
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- How to get post ID in a Page?
- Display an image if odd number of posts in grid
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- How to add div blocks after certain set of post
- How to avoid duplicates when creating recent network posts
- How do I remove a category from a wordpress loop>
- How to get the last category name of a child category?
- WordPress query undefined offset in loop
- WP_Query: getting posts where custom field exists
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Only show first image in foreach loop
- Get all posts as an array ID => Name
- How to hide posts of a specific custom category in WordPress?
- Post not populating for custom post type based on category selection
- Add new post in existing categories using wp_insert_post
- Problem with custom loop and wp_list_pluck [closed]
- Modify main query before it run without pre_get_post
- Displaying list of posts in category page
- Infinite Loop – WP_Query
- Loading Posts & Category with Ajax
- array_rand not working correctly?
- Dividing the loop to style post differently
- WP_Query() load selected post
- How to extract information from a wp_query result?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Display articles with a different template in the home page | Solved |
- in_array not working on dev server but works on localhost
- WordPress sorting posts by date and title using a dropdown
- posts_per_page displays only 2 posts instead of 4 posts
- Is there anyway I can call the year once?
- Need to show 7 posts from actual date
- Getting info about selected posts using one WP_Query
- How to display sticky post always at the top (before regular post) in wordpress?
- Return to the beginning of the results of a for loop
- Exclude category and post from loop in custom category.php
- How do if all posts has this category ID then do this
- Custom Post By Category
- Making list of posts with chosen description
- Get current_post in reverse order with pagination
- Add div after every 4 posts then every 2 posts for a responsive loop
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- Insert div after every three posts in home.php [duplicate]
- Only show current category post
- Unable to get Post Category Name and URL
- For each 3 posts, show a different post type
- Only Get A Certain Number of Posts From WP_Query
- Create a hierarchical loop at predefined markup requirements
- insert thumbnail image from php script
- Weird Behaviour: Not all WordPress Posts appearing
- Query category-specific, paginated posts and allow viewer to change sort order
- Query seems to be duplicated
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Make assigning post to a specific category equivalent to assigning it to all categories
- Error trying import one category on page
- Advanced Taxonomy query, with 3 post types
- Remove the_content From Loop
- Why does a meta_query break this WP_Query?
- Pagination in category.php not functioning
- Display post of specific category on page
- Fix incorrect related posts code snippet
- How to create a loop that will display one post and stop?
- Display all categories (with link) of custom post type – WordPress
- Count the number of matching post names in foreach loop
- How do I exclude the current post from the upcoming post query
- How to show correct td of table tags in wp_query loop
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?