Can we have a custom filter to show posts based on year & month & day on WORDPRESS?

77 Views Asked by At

I want to have a custom filter which simply shows all posts when I select year and/or month and/or day from any page?

Wordpress already have archive page where is show posts based on year/month/day. I want to give a custom form show anyone can select and go to that page.

1

There are 1 best solutions below

0
Abhay Vishwakarma On

We can use below HTML form to show the filter of Year/Month/Day.

<form name="my-post-filter" method="GET" action="/">
    
    <label for="post-year">Year</label>
    <select name="year" id="post-year">
        <option value="2023">2023</option>
        <option value="2022">2022</option>
        <option value="2021">2021</option>
        <option value="2020">2020</option>
    </select>
    
    <!--You can remove the below code if you dont want to show Month START -->
    <label for="post-month">Month</label>
    <select name="monthnum" id="post-month">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
    </select>
    <!--Month filter END -->

    <!--You can remove the below code if you dont want to show day START -->
    <label for="post-day">Day</label>
    <select name="day" id="post-day">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <!--Add remaining days -->
    </select>
    <!--Day filter END -->
    <input type="submit" value="Filter">

</form>

Note: If there is no post on selected filter then it will show This page doesn't seem to exist

You can add this in Widget as Custom HTML in sidebar/footer