Your problem comes from a fundamental misunderstanding of how WordPress loads the main loop.
Here you have a main query that goes and grabs the posts to display in your post type archive. It then decides to load archive-recept.php
based on that query.
The call to paginate_links
then provides the pagination for that main query. However, the main query isn’t being used.
Instead what you’re doing is ignoring the main query, calling your own query ( doubling the DB work involved ), then expecting the pagination links to give you pagination for your get_posts
query, rather than the main query.
This is functionally equivalent to calling query_posts
, which as we know is bad practice.
Instead, use the pre_get_posts
filter to modify the main query before it happens, e.g. something similar to:
function wpse182971( $query ) {
if ( $query-> is_post_type_archive && $query->is_main_query() ) {
$query->set( 'posts_per_page', '8' );
}
}
add_action( 'pre_get_posts', 'wpse182971' );