Support

Account

Home Forums General Issues Show only upcoming events from current month Reply To: Show only upcoming events from current month

  • The first problem you have is that you can’t use “Date” as the meta type because ACF date fields are not stored as “dates” in the database. the type needs to be strings or numbers.

    date('Ymt') will return the last day of the month for a given date.

    
    <?php
      $today = date('Ymd');
      $last_of_month = date('Ymt', strtotime(date('Y-m-d')));
      $args = array(
        'posts_per_page'  => 7,
        'post_type' => 'competicions',
        'orderby' => 'meta_value',
        'order' => 'asc',
        'meta_key' => 'datahora_prova', //ACF date field
        'meta_query' => array(
          array(
            'key' => 'datahora_prova', 
            'value' => $today, 
            'compare' => '>=',
          ),
          array(
            'key' => 'datahora_prova', 
            'value' => $last_of_month, 
            'compare' => '<=',
          )
        )
      );