Custom posts per page on Archive and Search in WordPress


Add the following to Functions.php in your theme or child-theme amd alter the posts_per_page argument value.

/**
 * Control the number of search results
 */
function custom_posts_per_page( $query ) {
    if ( $query->is_archive() || $query->is_search() ) {
        set_query_var('posts_per_page', 12);
    }
}
add_action( 'pre_get_posts', 'custom_posts_per_page' );

 


Leave a Reply