Recently I stumbled upon the following use case:
On my single-authors.php page (the detail page for an author), I wanted to showcase all the posts written by that author. (Note I created a custom post for author rather than using WordPress users since none of the authors log in to WordPress.)
To achieve this, I added the following to my functions.php:
add_action( 'template_redirect', function() { if ( is_singular( 'authors' ) ) { global $wp_query; $page = ( int ) $wp_query->get( 'page' ); if ( $page > 1 ) { // convert 'page' to 'paged' $query->set( 'page', 1 ); $query->set( 'paged', $page ); } // prevent redirect remove_action( 'template_redirect', 'redirect_canonical' ); } }, 0 ); // on priority 0 to remove 'redirect_canonical' added with priority 10 |