Support

Account

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

  • Thank you, but the code returns me nothing. Have I miss something?

    <?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' => '<=',
          )
        )
      );
        $upcoming_events = new WP_Query( $args );
        if ( $upcoming_events->have_posts() ) :
    ?>
    
    <?php while ( $upcoming_events->have_posts() ) : $upcoming_events->the_post(); ?>
    
    <div class="widget_next_competicions_title">
    <?php $permalink = get_permalink(); the_title('<a href="' . $permalink . '">', '</a>'); ?>
    </div>
    <div class="widget_next_competicions_date">
    <?php echo get_field('datahora_prova'); ?>
    </div>
    
    <?php endwhile; wp_reset_postdata(); ?>
    
    <?php endif; ?>