I’ve researched this issue, there are multiple suggested solutions but currently can’t find a sufficient solution that would help.
My custom post type pagination redirects to the homepage, the same solution working on by blog page.
inc/cpt.php:
register_post_type(
'casestudies',
array(
'labels' => array(
'name' => __('Case studies'),
'singular_name' => __('Case studie')
),
'public' => true,
'has_archive' => false,
'hierarchical' => false,
'show_in_rest' => true, // gutenberg support
'rewrite' => array(
'with_front' => false,
'slug' => 'case-studies'
),
// This is where we add taxonomies to our CPT
'taxonomies' => array( 'category' ),
'supports' => array(
'title',
'thumbnail',
'editor',
'excerpt',
'author'
)
)
);
template-casestudies.php
<div class="case-items--list grid grid-col-3 gap-48">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php $args = array(
'posts_per_page' => 6,
'post_type' => 'casestudies',
'category__not_in' => array(1), // 'uncateorized'
'paged' => $paged,
'orderby' => 'date',
'order' => 'DESC',
);
$wp_query = new WP_Query( $args );
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php get_template_part( 'partials/card','case'); ?>
<?php endwhile; ?>
</div>
<div class="columns is-centered mt-96-desktop mt-48 mb-128-desktop mb-48">
<div class="column is-12 has-text-centered navigation-wrap">
<?php if(!is_paged()): ?><span class="prev"></span><?php endif; ?>
<?php echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'prev_text' => '<svg class="prev" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M8.2002 13.5999L11.8002 9.9999L8.2002 6.3999" stroke="#2756FF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg><span>Previous</span>',
'next_text' => '<span>Next</span><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
<path d="M8.2002 13.5999L11.8002 9.9999L8.2002 6.3999" stroke="#2756FF" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>'
)); ?>
<?php if ( $wp_query->max_num_pages == get_query_var('paged') ) : ?><span class="next"></span><?php endif; ?>
</div>
</div>
I’ve tried:
- flushing permalinks
- post structure is set to /blog/%postname%/
- same code works on the blog page
- I would like to keep has_archive as false but even with archive true and archive.php as the listing still redirects to homepage
Pagination still redirects to homepage for /case-studies/page/2.
Any ideas would be welcome, thanks !
EDIT:
I also used to have a page case-studies which I deleted. It seems to be that likely some URL’s are causing this but could it be there are items in the database still after deletion and that might be causing it?
EDIT #2
If I have a template-casestudies.php with the slug /case-studie or anything else than /case-studies and has_archive => false then the pagination works. Seems like having the slug case-studies is conflicting somehow for the listing page.
If I have has_archive => true, delete the page template and just have the archive-casestudies the pagination doesnt’ work
0