How To Display Post In WordPress Between Specific Date

WordPress is always best option for blogging and other website as they have lot of way to customize the website. WordPress use by more than 20% out of total website on internet and I always find easy to edit my website as an armature developer.

WordPress display post specific date

There are many ways to display the post with specific date, but the best option I find it is using the arrays. You can use this code in category page, tag, home page or any place where you want to display the post. You can display from today or between certain future date for future posts. Find below the full code that you can post on page where you want to show.

WordPress WP_Query Code For Specific Date

<?php

$args = array(
'date_query' => array(

array(
'after' => 'June 1st, 2020',
'before' => array(
'year' => 2020,
'month' => 12,
'day' => 31,
),
'inclusive' => true,
),
),
'posts_per_page' => -1,
'cat' => 359,
'order' => 'ASC',
'orderby' => 'date',
);

$Specific_date = new WP_Query($args);

if($Specific_date->have_posts()) :
while($Specific_date->have_posts()) :
$Specific_date->the_post();
?>


<h1><?php the_title() ?></h1>

<div class='post-content'><?php the_content() ?></div>

<?php endwhile; ?>

</ul>
<?php else : ?>

<p>Sorry, but you are looking for something that isn't here.</p>

<?php endif; ?>
  • You can change date from after June to any.
  • You can change cat id number, that is category id.
  • If you want to show all post then do not change the number from -1. You can change with any number like 10, if you want to show 10 post.
  • Order ASC for ascending and DSC for descending .

Leave a Reply