Support

Account

Home Forums ACF PRO list by year Reply To: list by year

  • I have a solution now

    this is the code if anyone needs it:

      <?php if (have_posts()) : ?>
        <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $today = date('Ymd');
    
        $past_args = array(
            'paged' => $paged,
            'posts_per_page' => -1,
            'post_type' => 'exhibition',
            'meta_query' => array (
                array (
                    'key' => 'ex_start',
                    'value' => $today,
                    'compare' => '<',
                    'type' => 'DATE'
                )
            ),
            'orderby' => 'meta_value_num',
            'order' => 'DESC'                   
        );
        query_posts( $past_args );
        ?> 
    
        <!-- PAST EXHIBITIONS -->
    <?php while (have_posts()) : the_post(); ?>
    
    <?php   
        $date = get_field('ex_start');
        $past_year = DateTime::createFromFormat('Ymd', $date);
        $year = $past_year->format('Y');
    
        if ($year !== $today) { ?>
            <h2><?php echo $year; ?></h2>
        <?php } ?>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php $today = $year; ?>
    
    <?php
    echo "<p><br /></p>";
    ?>
    
    <?php endwhile; ?>
    <?php endif; ?>