Mika MAtikainen

Apr 15, 2020 · 4 min read

How to Customize number of search results in wordpress?

By default, the number of displayed search results is the same as the displayed number of posts (as set via your site’s Reading options). But sometimes, you want to display a different number of search results. Add this code to your theme’s functions.php to make it happen:
function wps_search_results_per_page($query) 
{
    global $wp_the_query;
    if (!is_admin() && $query->is_main_query()) {
        if ($query->is_search) {
            $query->set(‘posts_per_page’, 50);
        }
    }
    return $query;
}
add_action(‘pre_get_posts’, ‘wps_search_results_per_page’);
Here we are setting the number of search results per page to 50; feel free to customize that however is required.

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This