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
- retrieve thumbnail from post ID of best selling product in category
- Looking to exclude blog posts from category Previous/Next buttons
- Alter secondary loop to exclude posts from current page category
- How to display related posts from parent category
- User Defined order on get_categories?
- Search widget breaks when using multiple loops?
- Use template for posts with a particular category grandparent
- How to exclude specific category from the get_the_category(); array
- How to get to a specific position in wp_query?
- have_posts() execution failure
- How can I use wp_query to show all product data using just the products ID?
- Using foreach loop breaks
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How to store post ID’s in cookie or session to display the same posts later
- How can I add extra word in permalink when someone click download button?
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Alert Bar section within WP loop is displaying even though there are no posts
- Display category name only once inside loop
- 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
- Redirect to another page using contact form 7? [closed]
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- 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
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- 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
- Increment paged on WP_Query
- 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
- Echoing a CSS class based on category of post in a list
- 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?
- How to pick “full/thumbnail” images in the loop?
- WP_Query of Category Not Showing First Post
- Using multiple variables to assign categories to an array
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Pagination at category doesnt work with same name of page
- in_array not working on dev server but works on localhost
- 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
- Exclude category and post from loop in custom category.php
- How to display last whole post on the homepage
- 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
- Displaying 3 Category Posts differently
- 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
- List of child pages fetch next results at link click
- 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
- How to modify this function to exclude also the post belonging to a specific category?
- 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 do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress