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 →
TextWP PRO WordPress Theme

TextWP PRO

TextWP PRO is an more improved and advanced version of TextWP Free WordPress Theme. When compare with the TextWP free...

$25.00
FineWP PRO WordPress Theme

FineWP PRO

If you like free version of FineWP WordPress Theme, you will love the premium version. FineWP PRO is an improved...

$25.00
MagShow PRO WordPress Theme

MagShow PRO

MagShow PRO is the premium version of MagShow free WordPress Theme with more advanced features. MagShow PRO version has 160+...

$25.00
RapidWP PRO WordPress Theme

RapidWP PRO

Did you try RapidWP Free WordPress Theme?, Then you will love the premium version. RapidWP PRO is an improved, more...

$25.00
GridBone PRO WordPress Theme

GridBone PRO

$25.00
GridFeel PRO WordPress Theme

GridFeel PRO

$25.00
FlashWP PRO WordPress Theme

FlashWP PRO

If you like FlashWP free WordPress Theme, you will love the premium version. FlashWP PRO is advanced, more user friendly,...

$25.00
GridSoul PRO WordPress Theme

GridSoul PRO

$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.