pagination doesn’t show up for custom post type

Rather than attempt to fix your query, I recommend you sidestep it entirely by using custom post type archives!

With permalinks on, you should be able to view a list of all your movies posts by going to:

example.com/movies

Then, in your theme, create archive-movies.php, and it will be used instead of the archive.php/index.php for movies archives. Make sure to use the default loop not a custom loop, and WordPress will take care of the post type and pagination in your query.

To control how many posts are displayed on this archive, you can do a filter on pre_get_posts to modify the main query before it happens.

function john_movies_pagesize( $query ) {
    // exit out if it's the admin or it isn't the main query
    if ( is_admin() || ! $query->is_main_query() )
        return;
    // so its not admin, and its the main query, is it the movies post archive?
    if ( is_post_type_archive( 'movies' ) ) {
        // it is!! Set the posts_per_page to 6
        $query->set( 'posts_per_page', 6 );
        return;
    }
}
add_action( 'pre_get_posts', 'john_movies_pagesize', 1 );

Leave a Comment