# Posts per Page for Custom Post Type Archives

> Sets how many entries each custom post type archive shows, separately from the blog setting, for example 12 portfolio items or every testimonial on one page.

- Type: PHP
- Runs: Run everywhere
- Category: [Archives](https://wpide.com/library/category/archive/)
- Tags: post-types, pagination, archives
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/posts-per-page-for-post-type-archives/

## Code

```php
// Post type => number per page (-1 = all).
$wpide_archive_per_page = array(
    'portfolio'   => 12,
    'testimonial' => -1,
);

add_action( 'pre_get_posts', function ( $query ) use ( $wpide_archive_per_page ) {
    if ( is_admin() || ! $query->is_main_query() || ! $query->is_post_type_archive() ) {
        return;
    }

    foreach ( $wpide_archive_per_page as $post_type => $count ) {
        if ( $query->is_post_type_archive( $post_type ) ) {
            $query->set( 'posts_per_page', (int) $count );
            return;
        }
    }
} );
```

## Notes

Use -1 to show all entries on one page. WooCommerce products have their own setting and should not be listed here.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Posts per Page for Custom Post Type Archives" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
