How about something like this?
$args = array(
'date_query' => array(
array(
'before' => array(
'year' => 2013,
'month' => 2,
'day' => 28,
),
'inclusive' => true,
),
),
'posts_per_page' => -1,
);
$query = new WP_Query( $args );
Obviously you could set the exact date from a variable.
More info: https://codex.wordpress.org/Class_Reference/WP_Query
Related Posts:
- Custom Field sort not working (WP 3.8.1)
- Meta query with string starting like pattern
- Sorting posts by custom date fields (non standard date format)
- Using WP_Query To Get Posts Randomly From today
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- Get_post() with meta_key when compare is a date
- querying with custom meta field with meta_query
- Group posts by custom field
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- How to get the posts published in last two days using WP_Query?
- getting posts and number by specific meta value in multiple meta
- How to query using a combination of custom_field values?
- Revolution Slider Orderby Two Custom Fields
- Query two post types and order by two different date fields
- List taxonomy terms plus their latest post ordered by post date
- WordPress altering my custom query, How to fix it?
- Order by meta_key in custom post type doesn’t affect the query
- How to filter a dd/mm/yyyy date from a custom field in a query
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- How can i make WP_Query return post image and categories?
- Date query not inclusive despite parameter being true
- Use meta_query to display events by date in custom field
- wp_query with multiple custom fields
- How add a custom posttype name using ACF field to a query post array
- Query by custom dates in UNIX Time
- Display link to taxonomy archive only if it has posts with certain custom field values
- Ordering Posts Type A by Custom Fields of related Post Type B
- Order Posts by meta value AND published date
- Search Posts with Custom Fields as query
- wp_query add arguments using array_push if variable met
- Add quicklink to in the Admin posts page where I can query by a meta_key
- How to make Meta Query case sensitive?
- Display custom field meta outside loop, site wide
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- Meta_query with multiple keys and multiple values
- WordPress Comments sort by custom meta key
- Understanding the orderby in WP_Query?
- Extend product search with meta in WooCommerce
- How to list custom fields as headers and list all pages sharing that custom field under it?
- how to make members list directory through wordpress post custom meta key.
- Order by empty custom field
- Query posts without meta preload
- meta_value_num not ordering all items
- Posts published last 10 minutes
- Query all posts if multiple meta key don’t exist
- meta_compare not comparing whole integer
- wp_query to print posts if have X custom field value
- Why is WP_Query not displaying expected data?
- filter wp_query result with custom field values
- Order post type by sum of two custom fields
- WP_QUERY with group by with custom fields
- How to order posts on each different category?
- Intiger meta value with ‘>=’ returns posts with lower value
- Get every post with value in meta key
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- Order WP_Query results by meta key value in custom query
- Excluding posts with certain value of meta_key keeping posts without that meta_key
- WP Query and date format
- add_query_arg to compare and display events from a certain date
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- Sorting posts by Multiple custom fields in defined order
- How do i create a custom post query when the meta value is an array?
- How to add a “base” filter for all posts visible to visitors on the site?
- Sort custom post by custom field if none order by latest release
- WP Query – grouping posts by same meta key, adding together values from another key
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- meta_query is overriding default search
- Getting posts by custom field value
- Order 2 meta_queries differently in WP_Query?
- ACF Post Object meta-query by title not ID
- Order posts by title and custom field value?
- From admin edit user page query either the user_nicename or username field value of the user profile being edited or viewed
- Query by meta value (add a dropdown of all values)
- Order Posts By Custom Field That is an array of objects
- How to create URL parameters to run custom queries?
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- Meta key in wp_query bug?
- Custom WP_query and integrating into theme file
- Query by Category and Custom Field – Shortcode
- Wrap group of wp query posts to parent div by date/year
- Querying posts with meta key and meta value not returning anything
- Sorting posts by meta values: 2 different orders
- WP_Query with Pagination and orderby meta_value_num showing duplicates
- Mathematical operations on custom field values? (updated)
- Compare meta key separation
- WP_Query a custom field value bringing back 0 results
- Order by three custom fields (Y-m-d), then separate into yearly sections
- Using WP_Query to re-query and sort results using a date?
- Loop through multiple custom fields with increasing number
- new WP_query using custom fields
- WP_Query Sorting Posts by month … timeline effect
- query_posts with sorting on a custom datestamp
- query post based on comparison
- Query posts filter not working
- Display all custom meta field values from the database using ACF Repeater
- Taxonomy related query not working
- Get posts by meta value except one post [closed]
- Best performance for use Custom Field in WP
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string