Home Forums General Issues using datepicker to display posts on a page Reply To: using datepicker to display posts on a page

  • Your date formats are fine, but your meta_query logic is not.

    Currently your code will only display posts for events that are currently ongoing, i.e. for events that started in the past and will finish in the future (or start/end today). But it will not include events that are in the future that have not yet started.

    I think you can simplify your query by only filtering by the ending date, because in order to satisfy your requirements (only posts that are in the future, or today), it doesn’t matter when they started as long as they haven’t finished. And then to make sure you don’t get any events entered that end before they begin, I would use acf/validate_value to compare the two dates when the post is created.

    So your query arguments should be:

    $args = array (
         'category' => 1,
                'posts_per_page' => -1,
                'meta_key'       => 'date_debut',
                'orderby'       => 'meta_value_num',
                'order'          => 'ASC',
       'meta_query' => array(
                'key'       => 'date_fin',
                'compare'   => '>=',
                'value'     => $today,

    The only other issue you may have is with posts you created while experimenting with other date formats which may still exist in the database as saved.