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
- Preserving line breaks when saving and displaying custom fields data
- Custom field when adding new site to multisite networked WordPress
- Get custom field values into the sidebar/widget?
- Multiple custom fields with the same name
- Custom fields: In what order are they saved into the DB?
- BuddyPress – Hook to Update Custom Profile Fields [closed]
- Custom Fields Code not echoing whats in the value field
- Create WordPress shortcode with php code inside
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Hide custom column in admin template screen (Elementor) [closed]
- Get YouTube video id from url in a custom field
- How to insert multiple checkbox values into post as custom fields from frontend
- Fallback for empty custom fields
- Add a field to just ONE page
- get_post_custom_values problem, please help
- How To Save Data From Remote APIs To ACF?
- Check for meta data before it is published
- Sort custom fields in admin by last field added
- Call the latest posts from a custom field group to be displayed on front-page
- custom select field populated by allocated post category
- Adding thumbnails for non-image attachments
- Basics: adding template tag to display custom fields in the post
- get adjacent post by meta key and meta value
- file upload user profile
- Tons of Custom Fields [closed]
- 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)