How to display custom posts month by month?

wp-query be used to show posts month by month, and have it only show the past year

  <?php

$blogtime = date('Y');
$prev_limit_year = $blogtime - 1;
$prev_month = '';
$prev_year = '';

$args = array(
    'post_type' => 'asian',
         'posts_per_page' => 20,
         'ignore_sticky_posts' => 1
);

$postsbymonth = new WP_Query($args);

while($postsbymonth->have_posts()) {

    $postsbymonth->the_post();

    if(get_the_time('F') != $prev_month || get_the_time('Y') != $prev_year && get_the_time('Y') == $prev_limit_year) {

                   echo "<h2>".get_the_time('F, Y')."</h2>\n\n";

        }

    ?>

      <div class="td-pb-span3 padding-right-none">
	<div class="content-magazine"> <a target="_blank" href="<?php the_field('eastern_magazine_url'); ?>" class="magazine-section-img"><div class="overlay"></div><?php echo the_post_thumbnail($size);?></a> <span class="volume">Issue	<?php the_field('eastern_magazine_issues_no'); ?>
	</span> <a target="_blank" href="<?php the_field('eastern_magazine_url'); ?>">
	<h1>
	<?php the_title(); ?>
	</h1>
	</a> </div>
	</div>

    <?php

    $prev_month = get_the_time('F');
    $prev_year = get_the_time('Y');

}

        ?>
Social Share

2 thoughts on “How to display custom posts month by month?”

Leave a Comment