Shouldn’t this be easy?! Custom post type/custom taxonomy permalink

Follow the advice on this question as you did already, but add this to your code:

add_action( 'generate_rewrite_rules', 'fix_literature_category_pagination' );
function fix_literature_category_pagination( $wp_rewrite ) {
    unset($wp_rewrite->rules['literature/([^/]+)/page/?([0-9]{1,})/?$']);
    $wp_rewrite->rules = array(
        'literature/?$' => $wp_rewrite->index . '?post_type=literature',
        'literature/page/?([0-9]{1,})/?$' => $wp_rewrite->index . '?post_type=literature&paged=' . $wp_rewrite->preg_index( 1 ),
        'literature/([^/]+)/page/?([0-9]{1,})/?$' => $wp_rewrite->index . '?literature_category=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ),
    ) + $wp_rewrite->rules;
}

Lastly, go to Settings > Permalinks and hit save. If it still doesn’t work, save your permalinks again. Sometimes I feel like you have to save ’em twice, but who knows. Anyway, Let me know how you make out. Note that Computer Science Standard Answer #1 applies: It Works For Me… 😉

From the land of TMI…

For reference, the reason why the pages don’t work by default is that WordPress puts in a rewrite rule for literature/%literature_category%/%book%/%page%, which makes total sense if you think about it. So your default permalinks have these competing rules in this order:

[literature/([^/]+)/([^/]+)(/[0-9]+)?/?$] => index.php?literature_category=$matches[1]&book=$matches[2]&page=$matches[3]
[literature/([^/]+)/page/?([0-9]{1,})/?$] => index.php?literature_category=$matches[1]&paged=$matches[2]

All we’re really doing here is changing the order of these by unsetting the latter (we can keep it in, but then every rewrite thereafter has one more regex to run on page load) and adding it to the beginning of the array.

Fun fact: If you ever have a “book” entitled “page” and it has multiple pages, this order will conflict and its subsequent pages won’t work!

Leave a Comment