I want to sort my posts by year. Following code works almost perfectly.
But the current year (2017) is displayed multiple times although the other years are displayed just once (how it is supposed to be). I don’t understand the logic behind this. Thanks for your help!

2017
— Post 6
2017
— Post 5
2016
— Post 4
— Post 3
2015
— Post 2
— Post 1

    <?php

    $starting_year = date('Y', strtotime('+1 years'));
    $ending_year = 2010;

        while ($starting_year > $ending_year):

            $starting_year--;

                $args = array( 'post_type' => 'ausstellungen', 'posts_per_page' => 99999, 'cat' => 6, 'year' => $starting_year );
                $loop = new WP_Query( $args );?>

                <?php while ( $loop->have_posts() ) : $loop->the_post();?>

                        <a class="lesetypo medium"><?php the_date('Y');?></a>

                        <li>
                            <?php while ($year =! $year): ?>
                                <div class="hide">
                                <?php $slug =  $post->post_name;?>
                                <p><a href="<?php echo $slug ?>"><?php the_title();?></a></p>
                                </div>
                            <?php endwhile;?>
                        </li>

                <?php endwhile;

        endwhile;
    ?>

Read more here: Show WordPress posts in chronological order categorized in years


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: