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. Can I exclude a post by meta key using pre_get_posts function?
  16. Matching Serialized Arrays with meta_query
  17. Custom field metabox not showing in back-end
  18. So much data in postmeta
  19. How to hide meta box values from custom fields list?
  20. get_post_meta() unserialize issue – returns boolean(false)
  21. What is the advantage of the wp_options design pattern?
  22. How Can I save multiple records in same meta key?
  23. Trying to perform complex custom field query with order by set to field value
  24. Up/Down voting system for WordPress
  25. post meta data clearing on autosave
  26. WordPress Search Custom Meta Field Only
  27. Loop through two different sets of custom fields
  28. Update meta values with AJAX
  29. Localized Date Format for Custom Field
  30. Custom fields to save multiple values
  31. Function to change meta value in database for each post
  32. Get aggregate list of all custom fields for entire blog
  33. Difference between ‘LIKE’ and ‘IN’ in meta queries
  34. WP_Query display next custom post from today’s date
  35. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  36. WP_Meta_Query causing long-running MySQL queries
  37. using multiple meta_key and meta_value in query_posts
  38. Adding custom fields (post meta) before/during wp_insert_post()
  39. MySQL Query that looks for post with Custom Field, then changes Category
  40. post meta getting deleted on save
  41. How to make Meta Query case sensitive?
  42. Custom field not updating when value is empty
  43. meta_compare seems to be treating values as strings instead of integers as expected
  44. Limit the number of acf content when displaying in post loop [closed]
  45. Read / Watch / Listen times – meta
  46. How to add custom metadata text box dropdown to sidebar in Gutenberg editor for all post types
  47. Alter main archive, to show posts with meta as last
  48. Displaying multiple URLs as custom field values
  49. Show values of custom post meta on ‘Add new post’ page?
  50. Custom post meta field effect on the performance on the post
  51. Use meta_query to get title of associated post
  52. Limits, not all post are showen when querying for posts by view count
  53. Display Custom Meta Box Field Only If Value is Present
  54. Stop sending email everytime I updates my post
  55. Best way to store everyday post views?
  56. WP Query – Is this correct?
  57. Unable to get specific value from post meta
  58. Custom meta is not being saved
  59. IF Custom field value equals ZERO
  60. How to use media upload on metabox post page without breaking TinyMCE?
  61. Let’s Create Custom Field Template Documentation
  62. Branch made by several custom values
  63. Looping inside block return
  64. WordPress creates new lines in postmeta table on post update
  65. Can I save post meta programatically without setting metaboxes?
  66. Insert image into sub-field with update_post_meta
  67. How to use conditional statement with custom field
  68. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  69. Best way to achieve multiple links in a post title
  70. How can I add/update post meta in a admin menu page?
  71. Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
  72. Get author total post votes from post meta
  73. custom filed from post in the side bar
  74. Making WP_Query limit results by date before today where date is a meta_query
  75. multiple meta_query and orderby question
  76. How to display custom fields in hestia theme
  77. Trouble with serialized metadata
  78. How to speed up post list slowed by update_meta_cache()?
  79. WordPress Blocks, setAttributes not saving
  80. SQL query to change the value of a Custom Field
  81. Custom meta POST request fired twice when updating a post in Gutenberg
  82. Add custom field information to source meta data
  83. Update custom field on page specific to logged in user
  84. Create Meta boxes dynamically
  85. Delete custom meta
  86. Check if value exists before saving
  87. Get meta value when the page is a blog archive
  88. wordpress simple post multi rating with post_meta and user_meta
  89. Query Posts Via WordPress URL
  90. Meta_query not filtering posts
  91. Complex WP_Query Using Post Date And Post Meta
  92. Querying meta values within an array
  93. Custom fields / meta box output
  94. Colecting values from custom field checkboxes and displaying them in the post
  95. Build Array from Input Fields question
  96. Dynamic background image used in css after selector
  97. How can i put a custom field inside this php
  98. 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)
  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
  • 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