Home » Snippets » WordPress Tutorials » You are reading »

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.

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;

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

Related Topics:

WordPress Tutorials
Building Your Website with WordPress? Learn How to Optimize it
Snippets
How to Use New Facebook API 2.7 for Fan Page and Post Share Count
Snippets
How To Fix Chinese Language WordPress Excerpts Issue
Snippets
How to Get Facebook Page Like Count Without Access Token
Different Post Count in WordPress Search and Archive Pagehttp://cdn.dezzain.com/1/2013/05/wordpress-tutorial-default.jpghttp://cdn.dezzain.com/1/2013/05/wordpress-tutorial-default-150x150.jpgRichie KS SnippetsWordPress Tutorialsfilter post count,php coding,posts per pageWordPress tutorial on how to set a different post count in WordPress search and archive page so you can reduce paging in the search result page for users. DEZZAIN.COM
Enjoy This Article?, Follow us or Share it smiley
viral and buzz WordPress theme

3 Comments Already

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

    Public CommentUserI 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. 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

    Public CommentUseri 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
    • hi jane, yeap you can listed a query by month also using $query->is_month()

      Member of DEZZAIN.COMAdministratorhi jane, yeap you can listed a query by month also using $query->is_month()

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


You can wrap php, js or style css code with [PHP]..your code...[/PHP]