WordPress
HTML
CSS
JavaScript
jQuery
SQL
PHP
WordPress Snippets

Code Snippet

By default, WordPress uses the value defined in Settings > Reading to set how many results appear on the search results page. This setting also sets the number of posts per archive page.

You may want this to be different for the search results page, especially if the formatting of the page is different.

PHP

Place the following code anywhere in your theme’s functions.php document.

				
					// limit search results per page
function search_results_per_page( $query) {
    if ( $query->is_search() && $query->is_main_query() ) {
        $query->set( 'posts_per_page', '10' );
    }
}
add_filter( 'pre_get_posts', 'search_results_per_page' );
				
			

Change the number on line 4 to however many search results per page you’d like to show.

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

WordPress
HTML
CSS
JavaScript
jQuery
SQL
PHP

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.