DEV Community

loading...

Fetch year-wise month list if have post in a particular month in WordPress

Yuvraj Khavad
Hi πŸ™, I'm Yuvraj, but you can call me Yuvi! I'm a web engineer πŸ‘¨β€πŸ’» and having a very deep interest in problem-solving and simplifying things.
・1 min read

Hey Namaste πŸ™,

In a one of the recent project, We have a requirement like need to display year-wise months at the right side of the page and on click any month have to display a list of the blog post of that month using ajax and have to disable month if there no any posts.

Check below screenshot for the better understanding.

Screenshot_3

For this, We used MySQL query,foreach and array. Please check below code.

If have a blog post in the month then values will set true.

Below is array output, you can use it anyplace as per your need.

Discussion (2)

Collapse
ajulcab profile image
AHIEZER JULCA BLAS

good solution

Collapse
yuvrajkhavad profile image
Yuvraj Khavad Author

Thank You @ajulcab