By default meta values will be treated as strings, leading to the result that you get. As you can see from the codex on wp_query you can force a comparison with different formats by defining a meta_type. Like this:
$query->set('meta_type','DATETIME');
Related Posts:
- Order by custom field date with ASC order
- WP_Query – Order results by meta value
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Max length of meta_value
- ORDER BY custom field value
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Sort posts by custom field numeric value using dropdown
- How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
- get_pages sort alphabetically by meta value
- Trying to perform complex custom field query with order by set to field value
- Order Posts by Closest Numeric Values
- Is there a way to do multiple ordering on a multiple meta_query?
- Assign/update the custom field value for all posts
- Order Custom post type loop by custom field (datepicker)
- Sorting within nested queries / multiple meta keys
- Ordering posts by anniversary using only day and month
- Order by Custom Field date not recognized
- Comments form custom fields order
- If value present, order posts by two consecutive custom fields
- How to break meta values into different items and avoid duplicates?
- WP_query : meta_key with custom rule for specific value
- Sorting posts by multiple values, combined
- Sorting posts by custom fields in meta_query
- How to sort category by custom field value
- trim custom field text value and show (…)
- Query post order by post and desc not working
- How to wrap meta values seperated by comma in ? [closed]
- How to create a Custom Meta Box with Name/Value Admin User Input Fields?
- Run a check for multiple meta key values
- Filter by custom field (meta_key) using JSON API
- Order RSS content by an advanced custom field value
- Removing link ” from ” on meta_value in custom feilds
- Alter main archive, to show posts with meta as last
- Sort alphabetically by custom field
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Change order of posts
- Meta query with multiple custom fields for archives page ordering problem
- Ordering posts by custom field named “date” in backend
- query posts custom field calculation value
- WP Query – Is this correct?
- Using abs() with custom field in orderby statement
- pre_get_posts : only get posts by wp_usermeta value
- ORDER BY custom field value out of where clause
- meta_value and meta_key filtering returning no posts [closed]
- IF Custom field value equals ZERO
- List custom field values in alphabetical order without repetition
- How to update a custom field in all posts with the value of another custom field in the same post?
- Update post meta custom field using block editor
- How to add custom filed value after in wp post title
- query_posts with meta_value
- Order custom fields alphabetically
- Ordering by ‘Title’ OR ‘Custom Field’
- Show array of meta_value in Edit Post Coloum
- Problem with writting correctly a query posts args in WordPress
- How to query posts by month based on date custom field?
- Making WP_Query limit results by date before today where date is a meta_query
- User query – getting values for custom meta keys/fields
- get posts based on non-single metadata
- Set class if a meta value is set within post archive
- Ordering by ACF custom field vaule
- Sort by an ACF field in a tax_query
- WordPress Admin – Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- (woocommerce) How to get product id form order id & then retrieve custom meta linked to product?
- Create Shortcode shows only posts with custom_field meta
- 4 Unique Random Posts based on Custom Field Values
- How to properly get popular Posts by multiple Values
- Order a query by meta_value and then by post_date
- Custom Field: Display only if a specific key is selected outside the loop
- Order by custom field in query multiple
- Can’t sort custom column on user.php by number / meta_value_num?
- WP Query Args – search by meta_key or title
- Saving multiple custom meta box fields
- get Custom field label (select/dropdown) on front end
- Can I count every article following extracted meta value?
- Best Practice for storing aggregate data by date or other criteria?
- Block Editor – Meta values not saved, meta changes to empty array on update
- Slow meta query with multi meta keys
- Custom Field Multiple Clauses
- Send Multiple Custom Field Values Through the URL
- $wp_query meta_key naming issue [closed]
- using multiple meta_key and meta_value in query_posts
- global function to apply filter to custom field
- WP_Query orderby not working with meta_value_num and menu_order
- How to add a new meta key and assign timestamp to posts
- Print custom field in Query Loop block
- Collect user custom field in product page woocommerce
- Custom field query without duplicates results
- Add a custom meta box for client to order CPT posts how they want
- querying a custom field
- Can’t get video meta from wp_read_video_metadata()
- How to write specific HTML code with a specific custom field? [closed]
- How to style posts selecting a CSS post_class (added through custom_fields?)?
- Meta query relation ‘OR’ not working as expected
- How to hide custom fields added by a plugin?
- Image upload and path to custom field
- Listing posts with a value in a custom field
- Using Customizer API vs Custom Meta Box for custom content
- Custom meta boxes – add php code inside?
- Display different category template if custom field is checked