For this to work reliably, the date format in the database should be yyyy-mm-dd. Comparison type should be DATE or NUMERIC. If you take the date of 25-04-2012 in present format and compare it numerically to the date 26-04-1986, you can see what the issue will be: 25042012 < 26041986
ALso- if you’re doing these queries in addition to your main loop, use a new instance of WP_Query.
EDIT-
there were a few errors you didn’t fix. note that this still won’t work quite right until you fix the date format.
<?php
$today = date('m/d/Y', strtotime('+2 hours'));
$the_query = new WP_Query( array(
'post_type' => 'events',
'posts_per_page' => 5,
'meta_key' => 'start_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'start_date',
'value' => $today,
'compare' => '>=',
'type' => 'DATE'
))
));
?>
Related Posts:
- Ordering posts by anniversary using only day and month
- Ordering posts by custom field named “date” in backend
- How can I query on the year part of a complete date in a custom field?
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- How to add a new meta key and assign timestamp to posts
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- Unique meta_key with array value vs repeated meta_key with single values
- Avoiding ACF get_field and returning to core WordPress function
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- change order of images attached to post
- Group Posts By Custom Meta Value: Date
- How to improve my non-unique metadata MySQL entries?
- Checking if field is set before comparing with meta_query in query_posts?
- WP Query Args – search by meta_key or title
- Can I exclude a post by meta key using pre_get_posts function?
- Matching Serialized Arrays with meta_query
- Custom field metabox not showing in back-end
- So much data in postmeta
- How to hide meta box values from custom fields list?
- get_post_meta() unserialize issue – returns boolean(false)
- What is the advantage of the wp_options design pattern?
- How Can I save multiple records in same meta key?
- Trying to perform complex custom field query with order by set to field value
- Up/Down voting system for WordPress
- post meta data clearing on autosave
- WordPress Search Custom Meta Field Only
- Loop through two different sets of custom fields
- Update meta values with AJAX
- Localized Date Format for Custom Field
- Custom fields to save multiple values
- Function to change meta value in database for each post
- Get aggregate list of all custom fields for entire blog
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- WP_Query display next custom post from today’s date
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- WP_Meta_Query causing long-running MySQL queries
- using multiple meta_key and meta_value in query_posts
- Adding custom fields (post meta) before/during wp_insert_post()
- MySQL Query that looks for post with Custom Field, then changes Category
- post meta getting deleted on save
- How to make Meta Query case sensitive?
- Custom field not updating when value is empty
- meta_compare seems to be treating values as strings instead of integers as expected
- Limit the number of acf content when displaying in post loop [closed]
- Read / Watch / Listen times – meta
- How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
- Alter main archive, to show posts with meta as last
- Displaying multiple URLs as custom field values
- Show values of custom post meta on ‘Add new post’ page?
- Custom post meta field effect on the performance on the post
- Use meta_query to get title of associated post
- Limits, not all post are showen when querying for posts by view count
- Display Custom Meta Box Field Only If Value is Present
- Stop sending email everytime I updates my post
- Best way to store everyday post views?
- WP Query – Is this correct?
- Unable to get specific value from post meta
- Custom meta is not being saved
- IF Custom field value equals ZERO
- How to use media upload on metabox post page without breaking TinyMCE?
- Let’s Create Custom Field Template Documentation
- Branch made by several custom values
- Looping inside block return
- WordPress creates new lines in postmeta table on post update
- Can I save post meta programatically without setting metaboxes?
- Insert image into sub-field with update_post_meta
- How to use conditional statement with custom field
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- Best way to achieve multiple links in a post title
- How can I add/update post meta in a admin menu page?
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Get author total post votes from post meta
- custom filed from post in the side bar
- Making WP_Query limit results by date before today where date is a meta_query
- multiple meta_query and orderby question
- How to display custom fields in hestia theme
- Trouble with serialized metadata
- How to speed up post list slowed by update_meta_cache()?
- WordPress Blocks, setAttributes not saving
- SQL query to change the value of a Custom Field
- Custom meta POST request fired twice when updating a post in Gutenberg
- Add custom field information to source meta data
- Update custom field on page specific to logged in user
- Create Meta boxes dynamically
- Delete custom meta
- Check if value exists before saving
- Get meta value when the page is a blog archive
- wordpress simple post multi rating with post_meta and user_meta
- Query Posts Via WordPress URL
- Meta_query not filtering posts
- Complex WP_Query Using Post Date And Post Meta
- Querying meta values within an array
- Custom fields / meta box output
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- Dynamic background image used in css after selector
- How can i put a custom field inside this php
- Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)
- Sort posts based on an acf field called fecha value return longtext ‘20240517’
- What is the best way to get a different post’s custom field/postmeta with js?