How to check if a certain month has posts or not?
-
I’m working on my own theme. On a single page I want to show links to the archives of the previous and next months. However, if that month contains no posts, I don’t want to link to it. How can I check of a certain month has posts or not?
This code for example gives me a link to the previous month.
get_month_link(get_the_time('Y'), get_the_time('m')-1)
If that month contains no posts, the link redirects to a 404-page. I’d rather not show the link at all.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to check if a certain month has posts or not?’ is closed to new replies.