Issue Description
Main blog pulls through say 6 posts. Then we have a custom post type where we use 3 posts. Pagination always breaks.
Code Snippets
function case_studies_pagination( $query ) {
//Are we on case studies?
if (get_query_var('post_type') == "cpt_casestudies") {
$query->set( 'posts_per_page', 6 );
}
}
add_action( 'pre_get_posts', 'case_studies_pagination' );
How to Fix the Issue
Use ‘pre_get_posts’, check we are on the right archive page, then set ‘posts_per_page’
Need to be careful here as we are setting the number of posts per page in a second place, so if we change this on the archive page, it needs changing here too.
References
Reference Description |
Reference Link |
---|---|
Wordpress Support |
View Page |