Wordpress : Pagination of ONLY ONE page redirects to Homepage

Viewed 1087

The problem I'm facing is that on one Page my pagination urls always redirect to the homepage. The urls behind the pagination buttons look correct ( domein.com/currentpage/page/2 ) but it always redirects. The template is a copy of a page where it works perfectly, with only the post type changed to fit the content of this page. The pagination is rendered correctly, so the number of pages and items on it are correct. Both use the same custom pagination. The same pagination works on multiple pages in my site, except this one

So this one works: https://www.startpuntonderwijs.nl/vacatures/

And this one doesn't https://www.startpuntonderwijs.nl/leveranciers/

I've compared both scripts extensively and they seem 100% equal except for the lack of filters in "leveranciers" which I don't need there, and the different post type used in the query.

Both links normal pages with their own template. Both have their own taxonomie's and posts with a matching post type.

<?php 
// Set counter to 0
$counter = 0;

// paged variable 
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

// find ID's of all posts with the needed post type    
$query_items = get_posts(array('post_type' => 'leveranciers', 
'post_status'=>'publish', 'posts_per_page'=>-1));

//create a new variable with the post ids
foreach( $query_items as $item ) {
    $allposts[]=$item->ID; 
}

// the query 
$wpb_all_query = new WP_Query(
    array(
        'post_type'      => 'leveranciers',
        'post__in'       => $allposts, 
        'paged'          => $paged,
        'orderby'        => 'date', 
        'order'          => 'DESC',
        'posts_per_page' => 10)
);

if ( $wpb_all_query->have_posts() ) : ?>
    <ul>

<!-- the loop -->
<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>

<!-- Presenting the info from the posts -->

<?php endwhile; 

if (function_exists('custom_pagination')) {
    custom_pagination($wpb_all_query->max_num_pages,"",$paged);
} ?>

Expected result would be that https://www.startpuntonderwijs.nl/leveranciers/page/2/ would result the second page of paginated results for "leveranciers"

But instead it always redirects to the homepage. and the "/page/2/" drops out of the url.

0 Answers
Related