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?
- SQL query based on two different custom field values
- Block Editor – Meta values not saved, meta changes to empty array on update
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- getting all values for a custom field key (cross-post)
- How to add a custom field in the advanced menu properties?
- Custom query with orderby meta_value of custom field
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- Using meta query (‘meta_query’) with a search query (‘s’)
- Can I exclude a post by meta key using pre_get_posts function?
- Add validation and error handling when saving custom fields?
- Show Custom Fields in Quick Edit
- Where are custom field values stored in the database
- Validating Custom Meta Box Values & Required Fields
- Add custom fields to wp native gallery settings
- How to fix missing custom fields after upgrading to WordPress 4.8.1?
- How to enable custom fields for pages (if not a bad practice)?
- How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
- Is there a way to set default custom fields when creating a post?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Custom field/meta populated by dropdown of existing posts?
- Difference between meta keys with _ and without _ [duplicate]
- Is there any action filter/hook for validating a custom field before publishing the post?