Initialize an array before the first loop:
$exclude = array();
Then add the ID of each post within the first loop to that array:
while ($query->have_posts()) {
$query->the_post();
$exclude[] = get_the_ID();
// etc...
Then use that array to exclude those IDs via post__not_in
in the second query:
$args = array(
'post_type' => 'page',
'post__not_in' => $exclude,
// etc...
Related Posts:
- Inject post (from specific category) between posts in Loop
- Count number of published posts by type
- Get taxonomy terms only of the WP_Query current posts
- How can I use wp_query to show all product data using just the products ID?
- How to store post ID’s in cookie or session to display the same posts later
- 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
- Modify main query before it run without pre_get_post
- Do not duplicate posts with multiple categories in multiple loops
- array_rand not working correctly?
- WP_Query() load selected post
- Wp Query : Order by distance lat,lon
- WordPress sorting posts by date and title using a dropdown
- posts_per_page displays only 2 posts instead of 4 posts
- Query on a repeater date (acf)
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Getting info about selected posts using one WP_Query
- How to display last whole post on the homepage
- Only Get A Certain Number of Posts From WP_Query
- 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
- Why does WP_Query show only the same post even with different categories and endwhile?
- How to modify this function to exclude also the post belonging to a specific category?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- How do I use WP_query with multiple post IDs?
- Disable Attachment Pages Completely
- is_page() not working from within a plugin
- Remove option to allow trackbacks/pingbacks from post page options
- How to get year, month and hour in WordPress?
- Passing JSON data from WP Query into AJAX causing NULL errors
- Display certain amount of posts on taxonomy archive page
- How to add 2 posts under another post? Formatting should be intact
- Print number of post (in reverse)
- How to display custom field on homepage
- Can an array be used as a meta_query value?
- Can’t increase posts_per_page by variable
- Automatically generate Post/Page from searched Database item?
- How to get 2 or multiple custom post types in wordpress functions.php
- Displaying a button on each post
- Use WP_Query in shortcode
- Automatically add custom CSS to new posts using a category template
- Why is variable not working on custom sql query using wpdb?
- How Display Posts on category
- Random order of WP_Query results with highest meta value
- Dynamic content based on a URL parameter
- remove post that has no content
- Custom posts in different columns style
- How to show only subcategories in parent category not parent category?
- Security for data obtained from the database
- WP Insert Post and then go to post
- How to retrieve the data from the sever and displaying it in a page?
- How to overwrite orderby with add_query_var
- Get latest post from all categories except one
- Parse error: syntax error, unexpected end of file
- Load Posts on Click via Ajax into a DIV
- get_the_ID() in the footer returns wrong value
- WP_Query multiple post results
- create front-end users post list by specific category
- Error display post thumbnails for previous and next post
- echo var into wp_query
- form $_post action value gets truncated after it passes through two forms
- Toolbar Hidden in a Virtual Page
- Add posts to custom table in database instead of wp_posts
- get value from get_post_meta then reuse it in another get_post_meta
- WordPress Post Block Element not properly parsed with the_content filter
- get different meta-data of a complicated query at the same time
- Build A Custom SQL Query for WordPress Search
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Using a new WP_Query inside the loop
- How to Send Pingbacks for all Posts in WordPress?
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- How to get specific multiple pages excerpts at homepage?
- Trying to get post ID outside loop on blog page
- Enqueue script only on child pages of custom post types
- Attach and retrive multiple pdf files to post or page
- Wp-query output correct, but the loop shows one less item (only sometimes)
- Get list of posts from attachment
- How to display sticky post always at the top (before regular post) in wordpress?
- When working with a post, almost all wp_postmeta are deleted
- How to get the posts that my following users are liked?
- Displaying POST content with HTML tags and all
- Pagination in WP Queries
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- direct query to post_meta table
- Get posts associated with media attachment
- Can’t put a hyperlink on Featured Post’s Image
- WordPress get_post_meta issue
- List sibling pages widget, exclude current page
- Display pages from specific page template
- Does wp_query and query_posts affect website performance? [duplicate]
- WordPress post pagination on custom template not working
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- How to display the date under the post title?