First, your date format has to be in descending order from largest to smallest units, i.e.: year, month, day, hour, minute, second, etc., otherwise MySQL can’t query or order on the field. In this example I use year – month – day:
$today = date( 'Y-m-d' );
$args = array(
'post_type' => 'vehicle',
'meta_query' => array(
array(
'key' => 'end_date',
'value' => $today,
'compare' => '>=',
'type' => 'DATE'
)
)
):
$query = new WP_Query( $args );
Related Posts:
- Using WP meta query to show custom post types by a start and finish date
- Order Wp Query by earliest of 3 dates meta query
- WP_Query() displaying past post / event
- Mixing regular and custom post types (with meta_query) on home page
- WP_Query orderby custom field then post_date in one query
- Filtering a WP_Query meta_query by numeric values isn’t working
- How to sort CPT by custom meta value (date), and return posts month by month
- Using Query Posts With Multiple Post Types And A Taxonomy
- Date query for a custom meta field
- Can’t sort order of wp_query with 2 meta keys
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Combine tax_query and meta_query in WP_Query
- query order by date on custom type: wrong order
- exclude custom post type by meta key in wp_query
- Query current and future events, ordered by begin date
- Filter posts with meta_query NOT IN where value has multiple values
- Get the next event using date_query
- Filtering by Post Meta Custom Fields – Performance
- Is it possible to apply a meta_query to one specific post type in a query with multilple post types?
- Setting proper query for multiple custom admin filters
- WP_Query: include custom post type only with specific meta value
- Returning a list of custom post types excluding those without a specific meta_value
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- wp_query check if integer exists in custom field’s array
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How to do WP_Query with two meta fields with orderby clause
- Stuck in Order by more then one
- Why is this query not working? (Standard posts + custom post type)
- Meta Query posts not showing on ending date of custom field
- Configuring a meta query with multiple post types that have the same relationship on a single page
- Possible to filter custom post type with multiple meta data?
- Query based on custom fields start and end date
- WP_query – Filter by tax_query and meta_query using multiple select
- Getting a custom post’s custom field based on another custom post’s custom field select
- find custom post type post by searching its custom field with my string
- WP_Query of custom post type sorted by meta_key has unexpected results
- Create a WP_Query where if the first value of the first row is equal to the second compare other value
- Query Posts, order by meta value
- WP_Meta_Query object with conditionals
- WordPress giving a 404 page when passing a year argument different than the current year
- Sorting by meta_key different to search criteria?
- Two queries – one with checkbox ticked, one without – comparing meta_query
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- Display post count for a specific month
- build child and anchestor three from post parent
- meta query condition don’t work
- Custom query result empty on page 2
- Use WP_query to match post types based on custom field values
- meta query multiple values for the same key
- Sort custom post archives by a meta value from a different custom post type?
- Custom post types – meta_query: search lesson which starts sooner
- post type => ‘any’ not applied my custom queries
- How to get the posts that my following users are liked?
- Meta_Query refuses to return results
- Not able to get my custom search result using meta_query and tax_query together?
- Querying, storing, and using data from 2 separate custom post types
- Query events post type after current date and timezone
- Conditional posts in WP_query for search
- Selecting posts older than the current Unix epoch timestamp
- Custom Query With Multiple Meta Key Value
- Trying to combine multiple WordPress queries
- Querying meta values within an array
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Create a list of months based posts
- WP Query Conditionally query meta and taxonomy
- Sort Order for a Custom Query in a Post Type Archive Not Working
- How can I generate a RSS feed based on a custom WP_Query?
- Search Custom Post Type with all meta attached?
- Custom post type loop split/ordered by taxonomy
- How loop through posts based on custom fields
- Sort by two dates. Default entry date and custom field if present
- Custom Post Types not showing, custom WP_Query
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- How to alter WP-JSON main query or best practise for custom endpoints
- Previous/Next Link by Meta Value in CPT
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Admin Custom Meta Box – Pull Last 5 Posts from Custom Post Type
- How to let users choose where to search for posts?
- WP_Query Custom Post Type if Category ID Equals
- Select2 AJAX and WP Query Returns ALL and does not filter
- WP_Query orderby not work with meta_key
- Returning a custom content types with meta values
- Searching post types
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- wp_query not returning my custom post
- Get next and prev item from custom WP_Query and Custom Post Type
- WP_Query: how to search tags in addition to a custom post type?
- Pagination Not Working When Used With WP_Query() `offset` Property
- How to select meta key in custom database query
- Comparing Meta Field date in WPQuery using Meta_Query?
- Help understand and create a loop with WP_query
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- Events with multiple event dates + permalink for each date
- Pagination not working on homepage
- How to query custom post then display sections by meta value
- Using tax_query to get single post per category
- Show Posts in Vertical Tabs with Scrollbar