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’ );

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

Richie KS

The creator and author of He also a WordPress, BuddyPress, BBPress and Ecommerce Theme Developer.

This Post Has 3 Comments

  1. beth

    I am really impressed along with your writing skills
    as neatly as with the format in your blog. Is this a paid subject matter or did you customize it your self?
    Anyway keep up the nice quality writing, it’s uncommon to peer a nice blog like this one these days..

  2. Jane Fey

    i have 30-50 post feed per day and wanted to list out posts by day. using this tips only different is using $query->is_day() works like charm. thanks

    1. Richie KS

      hi jane, yeap you can listed a query by month also using $query->is_month()

Leave a Reply