Tired of endlessly scrolling through WordPress posts to find a specific one or locate content from a certain month? While the default admin interface lacks a date filter, this guide will show you how to add one with just a few lines of code—no plugins needed.

Implement Code for Adding Post Filter in WordPress Admin
Step 1: Create a folder in the WordPress plugin directory called “filter-post-date”.
Step 2: Inside this folder, create a file named “filter-post-date.php” and paste the following code:
<?php /** Plugin Name: Filer Post By Date Plugin URI: https://itsmeit.co/ Description: Filter posts or Media by day or month in Admin management page. Version: 1.0.1 Author: Loibv Author URI: https://itsmeit.co/ Network: true Text Domain: filter-post-date Copyright 2024 Loibv (email: buivanloi.2010@gmail.com) */ class FilterPostByDate { public function __construct() { add_action('init', array($this, 'filter_post_by_date'), 99); } public function filter_post_by_date() { global $pagenow; if (is_admin() && in_array($pagenow, array('edit.php', 'upload.php'))) { add_filter('months_dropdown_results', '__return_empty_array'); add_action('admin_enqueue_scripts', array($this, 'jqueryui')); add_action('restrict_manage_posts', array($this, 'form')); add_action('pre_get_posts', array($this, 'filterQuery')); } } public function jqueryui() { wp_enqueue_style('jquery-ui', '//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.css'); wp_enqueue_script('jquery-ui-datepicker'); } public function form() { $from = (isset($_GET['dateFrom']) && $_GET['dateFrom']) ? $_GET['dateFrom'] : ''; $to = (isset($_GET['dateTo']) && $_GET['dateTo']) ? $_GET['dateTo'] : ''; echo '<style> input[name="dateFrom"], input[name="dateTo"]{ line-height: 28px; height: 28px; margin: 0; width:125px; } </style> <input type="text" name="dateFrom" placeholder="Date From" value="' . esc_attr($from) . '" /> <input type="text" name="dateTo" placeholder="Date To" value="' . esc_attr($to) . '" /> <script> jQuery( function($) { var from = $('input[name="dateFrom"]'), to = $('input[name="dateTo"]'); $( 'input[name="dateFrom"], input[name="dateTo"]' ).datepicker( {dateFormat : "yy-mm-dd"} ); from.on( 'change', function() { to.datepicker( 'option', 'minDate', from.val() ); }); to.on( 'change', function() { from.datepicker( 'option', 'maxDate', to.val() ); }); }); </script>'; } public function filterQuery($admin_query) { if ($admin_query->is_main_query() && (!empty($_GET['dateFrom']) || !empty($_GET['dateTo'])) ) { $admin_query->set( 'date_query', array( 'after' => sanitize_text_field($_GET['dateFrom']), 'before' => sanitize_text_field($_GET['dateTo']), 'inclusive' => true, 'column' => 'post_date' ) ); } return $admin_query; } } new FilterPostByDate();
Step 3: Activate the “Filter Post By Date” plugin in your WordPress dashboard.
Note: If the filter doesn’t work, try deactivating other plugins temporarily to rule out conflicts.
If you encounter difficulties with the code or are not familiar with programming, you can download and install the ready-made plugin: https://github.com/itsmeit268/filter-post-date.
Adding a date filter to your WordPress admin panel can significantly improve your workflow. To further enhance your admin experience, check out our article on displaying featured images in admin for more efficient content management.