WP_Query does not support an exclude
argument. To exclude a post by ID, use post__not_in
and pass it an array of IDs.
Using your code above, your arguments could look like this:
$args2 = array(
'posts_per_page' => 3,
'post_type' => 'post',
'ignore_sticky_posts' => 1,
'orderby' => 'rand',
'tag__in' => array( $first_tag, $second_tag ),
'post__not_in' => array( $this_post2 ),
'date_query' => array(
array(
'after' => $date_to_compare,
'inclusive' => true,
),
),
);
Related Posts:
- Exclude post ID from wp_query
- How to filter by category in REST API, excluding posts also in other category term?
- Get attached media only
- WP_Query Excluding pages with Order is 0
- Query: offset post list, unless it’s a specific category
- Excluding pages in WP_query using ACF
- Exclude Category filter from Portfolio section
- Avoid repeated post on page 2 when excluding one on page 1
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Include posts from some categories while excluding from others
- Exclude current post from an array of posts?
- Exclude recently updated post from custom WP_Query using multiple loops
- How to exclude Sticky from Recent Post?
- specific post is not excluded from the loop
- Paginate wp_query while utilizing post__not_in
- WP Query Obj: Set value to be unequal | Hide media by admin
- Meta_query compare operator explanation
- Get array of posts from the current archive page loop
- Custom query incorrectly returning everything [closed]
- Last post ordered by publish date using WP_Query on front page
- Query certain amount of posts from multiple dates
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- Orderby = none not working [duplicate]
- Add inline HTML to posts published within last 24hrs
- Add and in the header while looping over custom query in page template
- Single page theme
- Pagination not working on static page
- WordPress pagination link always leads to home page
- Query posts with more than 20 comments
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- $wpdb->insert inserting two rows in database
- Custom Post order for homepage
- Arrange BBpress topics by created
- Warnings in nav-menu when visiting query pages [closed]
- Page navigation doesn’t show when query category
- Sorting posts DESC based on the number of comments using WP_Query
- Create unique page without header.php for json feed
- $wpdb select date range of posts
- Meta Query relation “AND” not working
- get_posts() not working with multiple statuses
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Performance when getting post meta for post retrieved by meta value
- Exclude an array
- How to use the query hook/filter?
- Cutom wp_query for geolocation search, pagination not working
- Tax query AND/OR meta query [duplicate]
- Help ordering Post loop by two meta values
- Display most popular in the past two days
- WP_Query (list) posts according to author’s custom field
- Need to convert string of term ids into comma separated integers for use in an arguments array
- How can I allow sticky posts but cap the query to 1 post?
- Hide posts with meta key in WP_Query
- How do I get my custom query to work with search results after the first page?
- Need Sub-category with main Category
- Loop doesn’t exclude the specified category in home page
- Easy way to write complex queries in wordpress
- Query_vars support in Rest API
- Continue or break the while loop
- Custom query filter by ACF date custom field
- Child pages not affected by orderby
- Sorting posts by Multiple custom fields in defined order
- Phpmyadmin – post editing
- Show multiple tax_query from 2 or more post_type in a single code
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- Query not sorting DESC
- How to use rewind_comments() – when and how to use it?
- How to make a query returning pages from multiple parents
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- create a custom query for posts managed by Restrict Content Pro
- How do I stop the same post showing multiple times in a archive?
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- how to get custom attachment url?
- WP_Query on custom key and value
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- How to break up output of posts for different terms on same page?
- How to mix two orderby-parameters into one ordered result
- Custom Post Type WP_Query with filters and search
- Get posts by similar names and categories
- Query by meta value (add a dropdown of all values)
- WP Query issue for multiple values
- Calling a function with WP_Query only ever brings the first result
- How To Query All Attachment Images Found In Post Galleries
- WordPress meta_query not working
- Filter WP_Query output before it is accessed (pre_get_posts)?
- $wp_query when new WP_Query
- Divide WP_Query posts by date & post type
- Unable to pass variable
- New WordPress WP Query using posts from certain categories
- Edit WordPress loop, taxonomies, & filter
- WP query based on two meta queries
- WordPress website links redirect to homepage
- How to display posts from a specific term first then another posts from another terms using tax_query
- Pagination only showed when no category is set in wp_query
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2
- Prevent URL Parameter Affecting other WP Query
- Sort by multiple columns using get_posts