Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

WP_Query of custom post type sorted by meta_key has unexpected results

I think the issue is that it’s being interpreted as a STRING type and being ordered character by character. Maybe try turning this into a meta query and forcing the DATETIME type like the example shown below:

'meta_query' => array(
    'starttime' => array(
        'key'   => 'start_time',
        'type'  => 'DATETIME',
    )
),
'orderby' => array( 'starttime' => 'ASC' ),

See WP_Query Custom Field Parameters

Related Posts:

  1. Ordering posts having multiple post-meta date fields
  2. Can’t sort order of wp_query with 2 meta keys
  3. query order by date on custom type: wrong order
  4. How to do WP_Query with two meta fields with orderby clause
  5. WP_Meta_Query object with conditionals
  6. Use WP_query to match post types based on custom field values
  7. Querying meta values within an array
  8. Order Wp Query by earliest of 3 dates meta query
  9. Query all posts where a meta key does not exist
  10. Meta query with boolean true/false value
  11. Get post with multiple meta keys and value
  12. Mixing regular and custom post types (with meta_query) on home page
  13. WP_Query() show posts that end later than today
  14. Sort Order for a Custom Query in a Post Type Archive Not Working
  15. WP_Query orderby custom field then post_date in one query
  16. wp_query check if integer exists in custom field’s array
  17. Previous/Next Link by Meta Value in CPT
  18. Get posts between custom dates
  19. Wp_query: sort by PHP variable
  20. A method for ordering mixed dates in search result loop (theory only, no actual code)
  21. Stuck in Order by more then one
  22. Why is this query not working? (Standard posts + custom post type)
  23. WordPress request fiter order by related post’s post_title
  24. Order Custom Post Type by Custom Field Value
  25. Change sort order when using ‘orderby’ => ‘type’
  26. Configuring a meta query with multiple post types that have the same relationship on a single page
  27. Ordering custom post type by multiple custom fields
  28. Possible to filter custom post type with multiple meta data?
  29. Query based on custom fields start and end date
  30. Displaying a div from an assigned meta_value when on a page
  31. WP_query – Filter by tax_query and meta_query using multiple select
  32. How to get specific post meta by title or id
  33. Getting a custom post’s custom field based on another custom post’s custom field select
  34. Having Issue on Ordering CPT by Custom Field In Custom WP Query
  35. find custom post type post by searching its custom field with my string
  36. $post->post_meta not pulling any post in wordpress/php
  37. Returning a custom content types with meta values
  38. WP_Query not resetting after wp_reset_postdata
  39. Create a WP_Query where if the first value of the first row is equal to the second compare other value
  40. Post ordering not working with custom field
  41. Query Posts, order by meta value
  42. Sorting by meta_key different to search criteria?
  43. Using WP meta query to show custom post types by a start and finish date
  44. Two queries – one with checkbox ticked, one without – comparing meta_query
  45. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  46. Displaying Portfolio Filter by Category Order (alphabetically)
  47. How to order query results based on if a custom field has been populated, then the order by the date of the post?
  48. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  49. Display Parent-Child Posts in specific order by comparing IDs in array
  50. How can I sort the results of a REST API response by the title of a connected custom post type?
  51. build child and anchestor three from post parent
  52. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  53. Order posts alphabetically with numbers but some of the posts has numbers in the title
  54. meta query condition don’t work
  55. Custom query result empty on page 2
  56. Orderby if between two meta fields
  57. How to sort by multiple values in a nested WP_Query
  58. Show posts from WP Custom Post Type selected from a field in a metabox
  59. SEARCH QUERIES – REVERSE OUTPUT
  60. Custom meta fields not showing up in WP_Response Object via custom endpoint
  61. meta query multiple values for the same key
  62. How to get post by meta value
  63. Sort custom post archives by a meta value from a different custom post type?
  64. Custom post types – meta_query: search lesson which starts sooner
  65. Wp Query sort order from custom MetaBox
  66. How do I get all authors posts of a custom post type outside loop
  67. post type => ‘any’ not applied my custom queries
  68. How to get the posts that my following users are liked?
  69. Meta_Query refuses to return results
  70. Linking posts together with Advanced Custom Fields “both ways”
  71. Not able to get my custom search result using meta_query and tax_query together?
  72. How to get Current week and current date record wp query
  73. How to get post meta for custom post type and taxonomy
  74. Querying, storing, and using data from 2 separate custom post types
  75. get_post_meta for Custom Post Type ( CPT )
  76. Query events post type after current date and timezone
  77. WP Query with multiple post types ordered by custom meta date then published date
  78. Conditional posts in WP_query for search
  79. Orderby modified only for specific post types
  80. Custom post order when using OR relation
  81. meta query always fails even if data is correct
  82. WordPress custom post type
  83. shortcode order for event custom post type
  84. Selecting posts older than the current Unix epoch timestamp
  85. Custom Post Type meta oembed html output resulting in WSoD
  86. Values inside a custom field to determine which category posts to display
  87. Custom Query With Multiple Meta Key Value
  88. Trying to combine multiple WordPress queries
  89. 404 on Pages for Custom Post Type & Query_Posts
  90. Custom Post Type + Custom Meta Query Not Showing 2012 Posts
  91. WP_query orderby not working after WP4.0 update [closed]
  92. Check for custom field value in different post type than current one and do something
  93. Query order by meta value force specific tag first
  94. WP_Query() displaying past post / event
  95. WP Query Conditionally query meta and taxonomy
  96. WP_Query not using relation key as expected and not producing any results
  97. WP Query filtering by custom category not showing all relevant posts
  98. getEntityRecords/useEntityRecords: How to use CPT metadata?
  99. Quering a post object based on another related post object
  100. Query multiple post types – Order by type and post title title
Categories custom-post-types Tags custom-post-types, meta-query, order, post-meta, wp-query
where is wordpress search pagination
Add value to new attribute inside WordPress menu items

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress