How to Display Search Results After a Specific Date in WordPress

To display search results after a specific date in WordPress, you can customize your theme's search query using the "pre_get_posts" action hook. This approach guarantees the display of only posts published after the specified date in the search results.

To filter search results after the specified date, add the following code to the functions.php file of your theme:

function themesdna_filter_search_results_by_date( $query ) {
    if( $query->is_main_query() && ! is_admin() && $query->is_search() ) {
        // Set the date to filter results after
        $after_date = '2022-04-20';

        $date_query = array(
            array(
                'after' => $after_date,
                'inclusive' => true, // Include posts published on the specified date
            ),
        );

        $query->set('date_query', $date_query);
    }
}
add_action( 'pre_get_posts', 'themesdna_filter_search_results_by_date' );

Note: Remember to replace "2022-04-20" with your desired date.

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
ListMode PRO WordPress Theme

ListMode PRO

$25.00
GridRead PRO WordPress Theme

GridRead PRO

If you like GridRead Free WordPress Theme, then you will love the premium version. GridRead PRO version has color options,...

$25.00
MaxWP PRO WordPress Theme

MaxWP PRO

If you like MaxWP free WordPress Theme, you will love the premium version. MaxWP PRO is feature-rich, easy to use,...

$25.00
ElegantWP PRO WordPress Theme

ElegantWP PRO

If you like ElegantWP free WordPress Theme, you will love the premium version. ElegantWP PRO is very user friendly, feature-rich,...

$25.00
Simple Grid PRO WordPress Theme

Simple Grid PRO

You'll be pleased with the Simple Grid PRO WordPress theme if you have tried the free version. It is a...

$25.00
FreshWP PRO WordPress Theme

FreshWP PRO

If you like FreshWP free WordPress Theme, you will love the premium version. FreshWP PRO is very user friendly, feature-rich,...

$25.00
GridMode PRO WordPress Theme

GridMode PRO

Are you using the GridMode free WordPress Theme and looking for more advanced features? GridMode PRO theme is developed for...

$25.00
TidyMag PRO WordPress Theme

TidyMag PRO

If you like TidyMag free WordPress Theme, you will love the premium version. TidyMag PRO is easy to use, feature-rich,...

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 55 WordPress themes.