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

Query post with meta_query where date is not in future

You might try adding a second meta_query that would look for anything without the meta key:

$args = array(
    'post_type' => 'agenda',
    'paged' => $paged,
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key'     => 'datum_event',
            'value'   => date('Ymd'),
            'compare' => '<='
        ),
        array(
            'key' => 'datum_event',
            'meta_compare' => 'NOT_EXISTS',
            'value' => 'placeholder'
        ),
    ),
);

Note that the value of placeholder is required to the make the not exists work – see https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

This is untested code but hopefully it helps!

Related Posts:

  1. Using OR conditions in meta_query for query_posts argument
  2. Query Custom Meta Value with Increment
  3. What is an efficient way to query based on post_meta?
  4. Select from wp_post and multiple meta_value from wp_postmeta
  5. Fetch Record based on meta key dates
  6. how to make members list directory through wordpress post custom meta key.
  7. How to increase load time of an archive/search page (WP_Query)
  8. How do i create a custom post query when the meta value is an array?
  9. I need query_posts() to order results first by a meta value and then by post ID
  10. How to search CPTs in draft using get_page_by_title()
  11. WP Query to order posts by multiple meta fields
  12. How to query post ids liked by the Author
  13. When should you use WP_Query vs query_posts() vs get_posts()?
  14. When to use WP_query(), query_posts() and pre_get_posts
  15. WP_Query with “post_title LIKE ‘something%'”?
  16. How to only display posts whose meta_value field is not empty?
  17. Get post ids from WP_Query?
  18. Nested meta_query with multiple relation keys
  19. Can wp_query return posts meta in a single request?
  20. order by numeric value for meta value
  21. Some doubts about how the main query and the custom query works in this custom theme?
  22. Wp get all the sub pages of the parent using wp query
  23. How do I query for posts by partial meta key?
  24. Pagination with custom SQL query
  25. Use REGEXP in WP_Query meta_query key
  26. How to query for most viewed posts and show top 5
  27. WP Query where title begins with a specific letter
  28. WordPress retrieving meta data for all custom post types in list view
  29. WP_Query vs get_posts
  30. Order by optional meta key?
  31. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  32. Whats the difference between post_limits and pre_get_posts?
  33. Reduce or prevent calling of update_meta_cache
  34. Is there a way to extend WP_query so Custom Post Types can have properties?
  35. Query Posts in a Predefined Order
  36. Order posts by ID in the given order
  37. What is the most efficient way of querying posts based on visits and date for current day?
  38. Is it possible to wrap Geo Location search around WP_Query?
  39. Getting attachments by meta value
  40. Query Multiple Post types each with own meta query
  41. WP_Query displaying ALL posts
  42. Get posts by menu ID
  43. Get the number of posts from the current page results
  44. Is it possible to select against a post’s parent’s fields with WP_Query?
  45. WordPress Custom Query to show posts from last x years
  46. meta_query where value is equal to given value
  47. Extending WP_Query — Optimise SQL query
  48. WP-CLI How to generate a list of posts with corresponding meta values
  49. How to know which one is the main query?
  50. Get posts by meta data OR title
  51. How to filter sql only for a specific post type
  52. Perform query with meta_value date
  53. Using is_main_query to select custom post type on certain page
  54. WP_Query ordered by custom field that is a date string?
  55. get query’s query string
  56. Meta Query with date and time on the same Day before given time
  57. get_the_title($postID) OR get_the_title()?
  58. How to make an activities stream mixing posts and comments?
  59. Display Posts by modifying the where clause only for my query
  60. SQL Statement generated by WP_Query not producing expected results
  61. WP_Query not working as expected for attachments and custom meta_query
  62. SQL query equivalent to WP User Query
  63. How do I create my own nested meta_query using posts_where / posts_join?
  64. How to count post meta key values for all posts in database
  65. How to use filter hook posts_join for querying taxonomy terms in posts_where?
  66. Best practice for multiple queries on page
  67. Group posts by meta_key
  68. How should I use posts_where to change meta_value from a string to integer?
  69. Recommended way to drop a pending query (in pre_get_posts)?
  70. How to Get All Posts but the Private ones?
  71. How can I create a WP_Query that returns posts where one meta_value
  72. how to retrieve specific product attribute value in an sql query?
  73. WordPress altering my custom query, How to fix it?
  74. WP Meta Query for some meta (array) values
  75. WP Query post meta value
  76. Would this post meta be better added to the post table rather than post_meta table
  77. Custom URl parameter
  78. query posts in functions.php and update a field
  79. Compile meta values from custom loop into array and then calculate sum total
  80. How to get sum of meta_values of a meta_key in wp_query according to conditions
  81. How to query ‘posts_per_page’ to display a different blog posts index template?
  82. how to fire join query with post_meta
  83. How to find out what “Blog pages show at most” is set to [duplicate]
  84. Best approach to create Hot and Trending sections
  85. WP_Query, custom sort and custom filter
  86. Multiple search queries on one page
  87. How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
  88. Pass the same object to multiple widgets in a template with one query
  89. Filter WordPress posts by between parameter
  90. Retrieve or Query Pages by ID
  91. SQL User Query by Multiple Roles using PHP
  92. Advanced WP Query hogs the SQL server
  93. Order posts by meta value and Date
  94. SELECT * FROM $wpdb->posts WHERE ID > 160
  95. Efficient way to update multiple post meta
  96. WP query exclude post within the last month / only show over 1 month old
  97. WordPress query for most recent posts from multiple categories
  98. How do you query wordpress posts using a math formula between multiple meta field values?
  99. How add a custom posttype name using ACF field to a query post array
  100. How to make orderby ‘meta_value_num’ OPTIONAL?
Categories wp-query Tags post-meta, query-posts, sql, wp-query
Loop (iterate) through Multi-Site sub-sites (blogs)?
Classic editor showing in Gutenberg when creating a custom post type

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