1

I've moved custom posts on what would normally be an archive template over to a dedicated page template. I've been following this article: https://jasonyingling.me/use-page-custom-post-type-archive-url-rewrites/.

But I'm confused about how I would add in pagination. If I inspect the code $paged is now always 0. When I call the code I've got here (<?php pagination(); ?>, nothing renders.

function pagination() {
    global $wp_query;

    $total_pages = $wp_query->max_num_pages;

    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

Any ideas what I'm doing wrong?

0

I think your query in the pagination function does not include your custom post type. Look at the Example With a Custom Query, where a category is set in the arguments. Also look how $paged is set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.