Custom post type (with parent-child relationship) singular page with pagination

I’m building a site that has two custom post types: Auction and Lot. Lots are connected to an Auction via the post_parent field.

The single-auction.php template show 9 lots of an auction using the following query:

Read More
$args = array(
    'post_type' => 'lot',
    'posts_per_page' => 9,
    'order' => 'ASC',
    'post_parent' => $auction_id
);
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query( array_merge( $args, array('paged' => $paged) ) );

The pagination, though, doesn’t work. When I go to:

http://domain.com/auction/{auction-title}/page/{page-num}/

WP redirects me to:

http://domain.com/auction/{auction-title}/

Therefore I can only see the first 9 lots of an auction.

Any ideas about what could be happening? I think that this issue is related to permalinks. I suppose WP expects an URL like this to paginate lots:

http://domain.com/lot/page/{page-num}/

But this lists ALL lots.

Any help would be appreciated.

Thanks!

Related posts

1 comment

  1. I managed to find a solution to my problem. Paste the following code into your functions.php file:

    function my_redirect_canonical($redirect_url) {
        if (is_singular('auction')) {
            $redirect_url = false;
        }
        return $redirect_url;
    }
    add_filter('redirect_canonical', 'my_redirect_canonical');
    

    Can someone please tell me what the redirect_canonical filter does? I’ve read some people recommending against touching it.

    Thanks

Comments are closed.