Did you chceck the Codex Date Parameters ? Expecially the ‘before’ param.
It works like this:
$date = get_the_date('Y-m-d H:i:s');
$args = array(
'date_query' => array(
array(
'before' => $date
),
),
'posts_per_page' => 10,
);
$query = new WP_Query( $args );
Related Posts:
- How can I query all users who registered today?
- How to display lastest post date in the homepage?
- How to display all posts with today’s same month and day only?
- WP Query Sort by meta value (date)
- How to get events using multiple custom meta fields?
- empty query breaks other queries
- Restrict query to last day with posts
- How to rearrange a pool of posts joined using two queries?
- Formatting a date/time returned from a custom $wpdb query
- Create a new post on a specified publish date via link?
- YearMonth datequery
- About WP’s save_post action
- How to compare dates in Java?
- How to Optimize WP site for millions of posts
- Get Terms by IDs with IDs order
- wpdb get posts by taxonomy SQL
- How to List Events by Year and Month Using Advanced Custom Fields?
- How many WordPress SQL Queries per page?
- Slow wp_enqueue_media()
- Advanced Custom Fields – Query Efficiency
- Get a user’s most recent post title
- Different Main Navigation per category
- How to tell if $query_var isset?
- Show All Posts Insert Edit Link
- Get posts by category with pure SQL query
- can’t get query to order posts by acf datepicker
- Sorting Grids with Essential Grid and Events Manger
- The use of including upgrade.php when building custom queries
- Get the timout value of a saved transient?
- Help with wordpress custom query and advanced custom fields plugin
- Does meta_query work within get_posts array?
- Mysql / WordPress killing my server with 80k users [closed]
- Slow meta_query with about 4 milion record on wp_postmeta
- How to show more than 5 posts?
- Deleting data from a custom table in WordPress
- WordPress Find Duplicate Post By Content
- mySQL query. ORDER BY meta_key
- how to query multiple categories in wordpress?
- Disable the MySQL query in the main query
- Strange string in console from wpdb query
- Update slug (URL) of pending posts via phpMyAdmin
- How can I get the query that would be run for the archive page?
- Query metas (and not : query posts by metas)
- Select query for a login
- What’s wrong with my $wpdb prepare?
- where should I reset query after using get_results?
- Missing posts in a query
- Alter a specific query on WordPress
- Exclude featured image and custom field from this get_attachment query
- Protect sequence of pages with same password for each of two groups of users
- How is it possible to get top comment from all children?
- wpdb print all post meta
- Form and custom query problem
- Export Specific User data without plugin
- How to write: $wpdb->update having WHERE NOT value pair in the array
- Exclude all sticky posts front page twenty twelve
- All in One Calendar Plugin Custom Post Type Query [closed]
- Get Posts from Last 24 hours and Sort them via GD Star Rating
- wpdb COALESCE won’t work
- get csv of users with user_meta
- Custom SQL Query passing array to WHERE p.id
- Query does not return content
- Query posts dynamic date range
- Parse query filter in wordpress and relation
- get posts by tag to showing in a widget
- Querying with WP query using meta key price
- Re-sort get_posts query results
- How do I get all results from my query
- Taxonomy filter under Polylang
- How to create an overview of posts with the same tag?
- create a link to a random post within the current category
- Pagination not working on custom post types with rewrite slug
- JetEngine Query Builder – order by value from repeater
- Change pure SQL database query to WordPress post query?
- Filter orders by modify date
- How to add url parameter to every search query in SearchWp?
- custom sorting media with multiple filters – error: not unique table/alias: wp_postmeta
- How can I get posts by 2 meta keys, prioritising one of them?
- Heavy meta query causing SQL crash
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Sort by postmeta on when searching
- Pulling an ACF into a query
- Speed up search query that searches in post meta?
- implementing my wp_query using $wpdb class
- Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice
- Using cron for multiple queries
- very slow wordpress query with default query
- Sort loop with query in the link
- Custom Query problem access the values
- Set posts per page for parent category and it’s all children
- Exclude sticky posts from query
- list or get meta_key where meta_value is ‘something’
- If more than 1 image show post link?
- Rewrite Query_Var URL Parameter with Slug
- How to query different categories on index?
- How to specify what kind of is_single post?
- Can’t See Media Queries with Inspect Tool [closed]
- Print data from wordpress sql query
- Can I create my own query in wordpress with traditional methods?
- How to figure out correct wp_options to have autoload=’yes’