Skip to content

Commit fda4aa5

Browse files
committed
fix: custom permalink structures break pagination
1 parent 593840a commit fda4aa5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/php/archive.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$context['title'] = single_tag_title( '', false );
3030
} elseif ( is_category() ) {
3131
$context['title'] = single_cat_title( '', false );
32-
array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
32+
array_unshift( $templates, 'archive-' . get_queried_object()->slug . '.twig' );
3333
} elseif ( is_post_type_archive() ) {
3434
$context['title'] = post_type_archive_title( '', false );
3535
array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );

src/php/functions.php

+15
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,18 @@ function filter_password_protected_posts( $query ) {
123123
return $query;
124124
}
125125
add_filter( 'pre_get_posts', 'filter_password_protected_posts' );
126+
127+
/**
128+
* Normalize queries for paginated archive pages to support custom permalink structures.
129+
*
130+
* @param array $query_string - The incoming query string to be normalized.
131+
*/
132+
function normalize_pagination_query_strings( $query_string ) {
133+
if ( isset( $query_string['name'] ) && 'page' === $query_string['name'] && isset( $query_string['page'] ) ) {
134+
unset( $query_string['name'] );
135+
$query_string['paged'] = $query_string['page'];
136+
}
137+
138+
return $query_string;
139+
}
140+
add_filter( 'request', 'normalize_pagination_query_strings' );

0 commit comments

Comments
 (0)