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

Displaying posts with only upcoming dates according their custom field date value

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:

  1. Ordering posts by anniversary using only day and month
  2. Ordering posts by custom field named “date” in backend
  3. How can I query on the year part of a complete date in a custom field?
  4. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  5. How to add a new meta key and assign timestamp to posts
  6. How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
  7. Unique meta_key with array value vs repeated meta_key with single values
  8. Avoiding ACF get_field and returning to core WordPress function
  9. Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
  10. change order of images attached to post
  11. Group Posts By Custom Meta Value: Date
  12. How to improve my non-unique metadata MySQL entries?
  13. Checking if field is set before comparing with meta_query in query_posts?
  14. WP Query Args – search by meta_key or title
  15. SQL query based on two different custom field values
  16. Using meta query (‘meta_query’) with a search query (‘s’)
  17. Can I exclude a post by meta key using pre_get_posts function?
  18. Custom post meta field effect on the performance on the post
  19. How to get custom post meta using REST API
  20. Difference between meta keys with _ and without _ [duplicate]
  21. Orderby meta_value only returns posts that have existing meta_key
  22. What is the index [0] for on post meta fields?
  23. What is “meta_input” parameter in wp_insert_post() used for?
  24. How to enable revisions for post meta data?
  25. The “_encloseme” Meta-Key Conundrum
  26. ORDER BY custom field value
  27. Best way to programmatically remove a category/term from a post
  28. Using get_post_meta with new_to_publish
  29. Can I query custom meta data through WP_Query
  30. Add custom fields to search
  31. SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
  32. Matching Serialized Arrays with meta_query
  33. Custom field metabox not showing in back-end
  34. Meta Query with AND & OR?
  35. So much data in postmeta
  36. Can I count the number of users matching a value in a multiple value key?
  37. Getting attachments by meta value
  38. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  39. How to hide meta box values from custom fields list?
  40. Delete custom meta
  41. Query Posts based on custom field value
  42. Problem saving meta data
  43. Check if value exists before saving
  44. Echo out custom fields in comments
  45. Get meta value when the page is a blog archive
  46. Search one custom field?
  47. Can’t save meta field value if the title not set
  48. Create custom query for search?
  49. Display Data From This Custom Media Upload Meta Box?
  50. Save values generated via API as custom meta fields
  51. Query postmeta values, and return multiple post_titles for common meta value
  52. Filter query based on date in custom field
  53. When post is updated, custom metadata in text area field is overwritten
  54. Thirtieth century date for a post
  55. change attachment custom field onChange event
  56. Adding custom fields to images
  57. How to save dynamically generated value in post type?
  58. Order a query by meta_value and then by post_date
  59. wordpress simple post multi rating with post_meta and user_meta
  60. Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
  61. Query Posts Via WordPress URL
  62. wp_postmeta are updated for only one page
  63. update_post_meta not working in action hook
  64. how to show this part only in the single post page?
  65. Custom Field: Display only if a specific key is selected outside the loop
  66. WordPress archives by custom field and date
  67. Meta_query not filtering posts
  68. Complex WP_Query Using Post Date And Post Meta
  69. Display meta data from a custom field within plugin Category Grid View Gallery
  70. When editing a post with a custom meta box the values aren’t displaying correctly
  71. Display posts where date field matches current month?
  72. Hard Define Custom Field Value
  73. Querying meta values within an array
  74. Custom fields / meta box output
  75. If post custom meta data is not set, show normal state
  76. add_post_meta insert null value into Database
  77. Make Custom Fields Public in JSON – API
  78. How do i output images from URL’s added to the same custom field key
  79. Retrieving custom field as shortcode
  80. Colecting values from custom field checkboxes and displaying them in the post
  81. Build Array from Input Fields question
  82. How do delete a meta key?
  83. Filter Query Post by Custom Fields(by date)
  84. custom field with links
  85. add multiple values (array) to post meta_input
  86. Order by a meta field in query loop
  87. Dynamic background image used in css after selector
  88. How can i put a custom field inside this php
  89. Check for custom field value in different post type than current one and do something
  90. Dynamically update Custom Fields to display new dates
  91. 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)
  92. save all acf options in one meta_value [closed]
  93. How to add new Metadata options (Date, Author, etc.) for Posts?
  94. Saving multiple custom meta box fields
  95. Search for meta_query does not return any result if combined with title
  96. get Custom field label (select/dropdown) on front end
  97. Best Practice for storing aggregate data by date or other criteria?
  98. Block Editor – Meta values not saved, meta changes to empty array on update
  99. Sort posts based on an acf field called fecha value return longtext ‘20240517’
  100. What is the best way to get a different post’s custom field/postmeta with js?
Categories custom-field Tags custom-field, date, meta-query, post-meta
Travel Blog Plugins
migrate comments from old database to new database

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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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