Different Post Count in WordPress Search and Archive Page

You are currently viewing Different Post Count in WordPress Search and Archive Page

Different Post Count in WordPress Search and Archive Page

When using WordPress, usually in homepage, you’ll set the post count to 5-10 but if you have more than 100 posts and when users search your site, it may return search result that paging between 1-3 pages. In my experience, user tend not to browse to page 2 for the search result and this will cause some lost page views in your end. Here’s a snippet you can add to your functions.php that can help you set different post count in search, tag or archive page.

[php]if( !function_exists(‘post_count_on_archive’) ):
function post_count_on_archive( $query ) {
if ( $query->is_tag() || $query->is_search() || $query->is_archive() ) {
$query->set( ‘posts_per_page’, ’50’ ); /*set this your preferred count*/
}
}
add_action( ‘pre_get_posts’, ‘post_count_on_archive’ );
endif;[/php]

Now your tag, search and archive page will return 50 posts per page.