I want to make a simple calendar in my wordpress. I want to show every day different posts, which have the current date as tag.

For example, I put a tag 17-01-2017 in three posts. I want to get them as a list on 17-01-2017.

I have the following code, which works fine -

$wpb_all_query = new WP_Query( 'tag=something' );
<?php if ( $wpb_all_query->have_posts() ) : ?>
    <!-- the loop -->
    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <!-- end of the loop -->
    <?php wp_reset_postdata(); ?>
<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

However, I can't change the preset value "something" to show current date like 17-01-2017. Can you please, help me?


We can use e.g. current_time( 'd-m-y' ) to get the formatted current date. So you could try:

$wpb_all_query = new WP_Query( [ 'tag' => current_time( 'd-m-Y' ) ] );

Also note the date_query parameter, if you want to target the post date part instead.

  • You might also want to adjust the posts_per_page parameter of WP_Query. Hope it helps. @alexbg89 – birgire Jan 17 '18 at 8:30
  • 1
    @alexbg89 Just as an addition. Should you opt to use date_query, make sure to add future to the retrievable post_status types. – Nicolai Jan 17 '18 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.