I could achieve the following-

mydomain.ext/cpt

mydomain.ext/cpt/%custom_category%

mydomain.ext/cpt/%custom_category%/%cpt_post%

mydomain.ext/cpt/%custom_category%/%cpt_post%/some_endpoint

Everything works fine except

mydomain.ext/cpt/%custom_category%/page/2

Here is how I registered CPT and CPT Taxonomy-

    $args = array(
    "label" => __( 'Books', '' ),
    "labels" => $labels,
    "description" => "Life Science books useful for the preparation of CSIR-UGC NET, ICMR, DBT and various other life science examination. Also these books are helpful in study during graduate and post graduate courses. ",
    "public" => true,
    "publicly_queryable" => true,
    "show_ui" => true,
    "show_in_rest" => true,
    "rest_base" => "books",
    "has_archive" => "books",
    "show_in_menu" => true,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => true,
    "rewrite" => array( "slug" => "books/%book_category%", "with_front" => false ),
    "query_var" => true,
    "menu_position" => 5,
    "menu_icon" => "dashicons-book-alt",
    "supports" => array( "title", "editor", "excerpt", "author" ),
    "taxonomies" => array( "book_category" ),
);

register_post_type( "books", $args );



$args = array(
    "label" => __( 'Book Categories', '' ),
    "labels" => $labels,
    "public" => true,
    "hierarchical" => false,
    "label" => "Book Categories",
    "show_ui" => true,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "query_var" => true,
    "rewrite" => array( 'slug' => 'books', 'with_front' => false, ),
    "show_admin_column" => true,
    "show_in_rest" => true,
    "rest_base" => "book-category",
    "show_in_quick_edit" => true,
);
register_taxonomy( "book_category", array( "books" ), $args );


function books_permalinks( $post_link, $post ){
    if ( is_object( $post ) && $post->post_type == 'books' ){
        $terms = wp_get_object_terms( $post->ID, 'book_category' );
        if( $terms ){
            return str_replace( '%book_category%' , $terms[0]->slug , $post_link );
        }
    }
    return $post_link;
}
add_filter( 'post_type_link', 'books_permalinks', 1, 2 );

I tried WP_DEBUG, query_post('&paged='.$paged), or using WP_Query… But still it takes me to the 404 page…

[Please don’t ask to do flush the rewrite rule blah blah…]

Where am I wrong? Or what will help me to get the pagination work?

Thanks in advance.

Read more here: Custom Taxonomy Paging Error with CPT Base in Taxonomy URL Rewrite


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: