Here are two ideas for your date_query
part:
1) After 2 days ago
:
If you need posts published after current time, 2 days ago:
'date_query' => array(
array(
'after' => '2 days ago', // or '-2 days'
'inclusive' => true,
),
),
then the corresponding SQL part is:
post_date >= '2014-09-09 17:57:15'
if the current date-time is 2014-09-11 17:57:15
.
2) After midnight 2 days ago
:
If you need posts published after midnight, 2 days ago:
'date_query' => array(
array(
'after' => 'midnight 2 days ago',
'inclusive' => true,
),
),
then the corresponding SQL part is:
post_date >= '2014-09-09 00:00:00'
if the current date-time is 2014-09-11 17:57:15
.
You can than easily modify this to other day periods.
Related Posts:
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Using WP_Query to re-query and sort results using a date?
- Return only Count from a wp_query request?
- Make a WP Query search match exactly the search term
- WP_Query: query posts by ids from array?
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query WooCommerce orders where meta data does not exist
- pre_get_posts with get_posts
- Using WP_Query To Get Posts Randomly From today
- author.php with ACF and CPTs
- Query Custom Meta Value with Increment
- Identify which loop you are hooking into; primary or secondary?
- How to make an activities stream mixing posts and comments?
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- SQL query equivalent to WP User Query
- Finding the next 5 posts
- List taxonomy terms plus their latest post ordered by post date
- Foreach-generated custom tax queries, each with an ajax “Load more” button
- view queries made?
- meta_query on a date range using an array of values
- WP_Query Performance Issues with meta_query
- How to detect custom query inside `posts_where` hook?
- Pass the same object to multiple widgets in a template with one query
- Is temporarily overwriting $wp_query a bad idea?
- Use meta_query to display events by date in custom field
- How to output different posts per page?
- What is considered a default query for the request filter?
- $wpdb insert is not work
- Pass array of taxonomy terms to wp_query
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- merge two query arguments into one WP_Query call
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- Query: offset post list, unless it’s a specific category
- How to reduce the number of queries?
- How to query a custom post type with a taxonomy filter but display post type archive page?
- List of the years with posts presented
- Query custom post type by custom taxonomy (category slug)
- Change query_posts to WP_Query in page but does not work
- Optional Meta Query
- Set conditional on template based on referring page slug
- Editing the default wordpress search
- Iterating through $wpdb query without using get_results for large query results
- Weird orderby => post__in issue
- Slow page loads due to WordPress Core Query
- Filter posts in category archive page by year using a dropdown
- Set global $wp_query/$post variable for dynamic page generation
- Include data from custom table in WP_Query
- Meta Query relation “AND” then set array accordingly
- How to get a query variable?
- 2 weeks ago from meta query meta value
- date_query seems to be ignored by wp_query
- Better wordpress attachment query than this
- Sort WordPress Posts Meta value by Week not Day
- Is_single() conditional tag returns null in query
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Is it possible to query from external database? [duplicate]
- Can’t sort custom post type by random
- Query posts that contain video?
- Show a 404 error page if Public query variable’s value doesn’t exist?
- How to set up hierarchical relationships without using plugins / meta query
- Set front_page programatically after user login via query, while leaving site option alone
- How to filter query loop block with a search string from the query parameters
- mysql query order by
- Notice thrown when creating numeric pagination on custom query
- wordpress udpate query not equal to
- How to SQL query posts IDs by categories AND authors?
- meta_query where the meta value is not the post title
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Pagination of custom page with custom fields query
- setting offset to category number in archive page
- Woocommerce Get Orders By Meta Value
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Move some posts to end of sort order, even if there is a sort in the wp_Query already
- Query Posts | Combining multiple form inputs into query arguments to generate one filter result
- How to query 5 users in random who have published more than 10 posts
- Is my code correct?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Meta query doesn’t remove placeholder escape before query
- How to show post title in content editor in backend?
- Merge two queries and remove duplicate
- What is the best way to reset a search on a meta_key / meta_value?
- How can I modify standard search query to include also ACF custom fields values?
- Bring a post to the top of the query if it’s in a certain category?
- WP_Query with child element
- Custom pagination (Title, date and teaser)
- Using URL variables on a custom WP_Query
- How to get query results for the next page
- Pagination is not working on custom query inside a custom home page template
- Loop through multiple custom fields with increasing number
- How to organize a WP_Query’s list of posts by category and display category title?
- Need help setting up a search form for wordpress [duplicate]
- WordPress Query showing multiple titles
- custom query to get posts
- confirm my booking with phone number
- Get WP_Query query after execution?
- shortcode using multiple WP_Query’s with multiple category names not fully functional
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- How to get posts that have certain meta key value and order based on another meta key’s value