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

Show future events based on custom field AND order by date

I found the actual issue so I thought I’d update.

ACF documentation says to use $today = date (‘Ymd’) to compare dates but you really need to use current_time(‘Ymd’) so I removed the functions.php code that I added and fixed the problem rather than work around it.

Here’s my query now

$event1 = current_time('Ymd');
    $args = array(
        'post_type' => 'events',
    'post_status' => 'publish',
    'posts_per_page' => '10',
    'meta_query' => array(
        array(
            'key' => 'event_date_ends',
            'compare' => '>=',
            'value' => $event1,
            )
            ),
    'meta_key' => 'event_date_ends',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
);

So for your query try this

$today = current_time('d M, y');

$args = array (
    'post_type'              => 'event',
    'meta_query'             => array(
        array(
            'key'       => 'date',
            'value'     => $today,
            'compare'   => '>=',
        ),
    ),
    'meta_key'               => 'date',
    'orderby'                => 'meta_value',
    'order'                  => 'ASC'
);

Just make sure the current_time (‘d M, y’) is how you have your data being stored via whatever date picker you’re using or if you’re typing it in each event in a field that’s how you’re typing it in. d M, y would read 19 Jun, 14. Remember your display date and stored date can read differently. I hope this helps.

Related Posts:

  1. Query all posts where a meta key does not exist
  2. what is the correct way to compare dates in a WP query_posts meta_query
  3. Get post with multiple meta keys and value
  4. Echo all meta keys of a custom-post TYPE
  5. How can I filter posts by post_parent in the admin?
  6. Post metadata deletes itself
  7. How to create a mini directory in WordPress?
  8. Detect meta value changes when post is updated (post_updated)
  9. Search everything (posts, pages, tags, cpt, meta)
  10. Custom Post Type: Set post_title equal to a custom post type field
  11. I can’t set meta_key in my custom post type query
  12. Can’t sort order of wp_query with 2 meta keys
  13. How to get source of custom meta image?
  14. How can I include meta box content when searching?
  15. update a post meta from a single table cell TablePress
  16. Displaying Meta Box Image
  17. Automatically adding meta data to posts or multiple query help
  18. Trigger “unsaved changes” dialog for custom post meta changes
  19. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  20. Displaying custom posts only if custom meta box’s date is not expired
  21. Displaying Metabox value (custom post type taxonomy)
  22. How do I sort a custom post type admin column using two meta keys?
  23. How can I display my custom metaboxes on a custom post template?
  24. get_post_meta is returning image id
  25. Custom Post Type, Saving Multiple Checkboxes
  26. Create a random unique 6 digit number as custom field for custom post type
  27. Export entries and multiple custom field meta to .csv?
  28. how to interconnect custom post types?
  29. Metadata for a taxonomy – is there any WordPress way of doing this?
  30. orderby in custom WP Query does not work
  31. Update CPT post meta with update_post_meta and cron job
  32. Insert post metadata for all posts in CPT at once if metadata no existent
  33. Display custom post type from dynamic custom field
  34. Populate dropdown from one custom post type inside another custom post type
  35. Notice: Undefined index: error and understanding wordpress
  36. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  37. Get posts between custom dates
  38. Deleting Custom Posts & Meta Data on Uninstall
  39. How do I create an archive page as a including metadata?
  40. A better way to add a meta box to custom post types
  41. Two Custom Post Types Many to Many Relationship
  42. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  43. post meta parameter in post custom-post-type endpoint with restapi
  44. How do I set all of a particular post meta to a value within the custom post type I’m in?
  45. Update postmeta Parent when post_status child change
  46. Update database from Quick Edit according to Checkbox state of Custom Post Type
  47. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  48. Dynamic Custom Fields
  49. Show Custom Post Type meta boxes only on Page Edit
  50. Custom filter function not working with Custom post type
  51. Custom fields for custom post type
  52. If Post Meta Equals Current Title Conditional Advanced Custom Fields
  53. create custom meta box with default value
  54. Issue on Working with Metabox – Checkbox to enable Sale Items
  55. delete_post_meta() for whole CPT / multiple posts?
  56. How to move a post to different post type with all meta data?
  57. Why do I have to press the “Update” button twice to save my meta box values?
  58. how to show records that don’t have custom meta value
  59. WP API Response does not show my registered metadata
  60. How to detect that the save_post hook is calling the callback associated to the current edit post page only
  61. Problem with adding custom post type meta to header by plugin
  62. How to call a post’s metadata in shortcode.php?
  63. Echo custom post meta from options array
  64. Value of post meta dropdown is not showing in WordPress
  65. Get all metadata for a given custom post type
  66. WP_Meta_Query object with conditionals
  67. Trying to write shortcode with get_post_meta but isn’t working
  68. Advanced custom field – posted fields from custom post type
  69. updating one custom meta field only
  70. Add a class to post_class if more than one post shares same meta_value_num
  71. Function to return values from metabox
  72. Add a meta field to the list of results for a custom post type
  73. Custom fields for post or terms which don’t update on post update
  74. Should I use a custom taxonomy or custom post type for grouping a list of panels associated with a group of tests?
  75. Add a form in every post and save data in post meta
  76. How to use multiple Meta Field from CPT as Post permalink
  77. How can I add a meta[] to my custom post type and search by term with the Rest API?
  78. Show posts from WP Custom Post Type selected from a field in a metabox
  79. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  80. Peepso: Add extra data field (custom post meta) to postbox
  81. Change picture attachment meta of all occurrences of a picture
  82. Unknown Post Meta Records
  83. Get Previous Post based on Custom Field Name, for Custom Post Type
  84. Saving custom post types post_meta over REST-API fails
  85. How to Disable option of meta field if that option is selected for any other post in custom post type?
  86. How to get post detail based on URL of the post
  87. Linking posts together with Advanced Custom Fields “both ways”
  88. Stripe multiple transactions
  89. How to get Current week and current date record wp query
  90. Edit is changing my custom’s post type parent id
  91. How to add post reference field to a plugin?
  92. WordPress custom post type
  93. Edit post meta direct from post.php?
  94. Custom Post Type meta oembed html output resulting in WSoD
  95. Timetable of Custom Meta Data using Custom Post Type and Custom Taxonomy
  96. Change the contents of a dropdown through the admin panel?
  97. fetch meta fields inside a widget
  98. Custom post type – update_meta not working
  99. Use a Variable in update_post_meta as the $meta_key
  100. getEntityRecords/useEntityRecords: How to use CPT metadata?
Categories custom-post-types Tags custom-post-types, post-meta
Additional fields on Woocommerce’s rating system
Is there any hook for theme activation ? or something similar?

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