I have a custom post type with courses-events
as the slug.
In functions.php, I have:
add_action( 'pre_get_posts', 'custom_archive_items' );
function custom_archive_items( $query ) {
if ($query->is_main_query() && !is_admin() && is_post_type_archive( 'courses-events')) {
$query->set( 'posts_per_page', '1' );
}
}
I know the above is firing for my archive page if I dump $query in the condition, it is visible.
On archive-courses-events.php I have simply:
if ( have_posts() ) :
while(have_posts()) : the_post();
<!-- my output -->
endwhile;
echo paginate_links();
endif;
I have 2 posts and as posts_per_page
is set to 1, but 2 posts appear and I do not see pagination.
I don’t understand why this isn’t working as everything I’ve read says that this is the minimum necessary for this to work?