Support

Account

Forum Replies Created

  • no that code is for template files such as page.php

  • I solved like this:

                <?php
    
                // get today's date
                $today = date( 'Y-m-d' );
    
                // get posts
                $futureposts = get_posts(array(
                  'post_type'   => 'eventi',
                  'meta_key' => 'event_date_start',
                  'posts_per_page' => -1,
                  'orderby' => 'meta_value_num',
                  'order' => 'ASC',
                  'meta_query'=> array(
                      array(
                        'key' => 'event_date_start',
                        'compare' => '>',
                        'value' => date("Y-m-d"),
                        'type' => 'DATE'
                      )
                  ),
              ));
    
                if( $futureposts ): ?>
    
                    <ul class="events-list">
    
                    <?php foreach( $futureposts as $post ) : setup_postdata( $post ); ?>
    
                        <li>
                            <div class="entry-content">
                                <?php the_field( 'event_date_start' ); ?>
                                <?php if( get_field( 'event_date_end' ) ) :
                                    echo " - ";
                                    the_field( 'event_date_end' );
                                    endif; ?>
                                <br />
                                <a href="<?php the_permalink(); ?>">
                                  <?php the_title(); ?>
                                </a>
    
                            </div>
                        </li>
    
                        <?php wp_reset_postdata(); ?>
    
                    <?php endforeach; ?>
    
                    </ul>
    
                <? else: ?>
    
                    <p><?php _e( 'No upcoming events are currently on the calendar.' ); ?></p>
    
                <?php endif; ?>
  • ok but what is the code to print the foreach?

    thank you

Viewing 4 posts - 1 through 4 (of 4 total)