Skip to content

Commit

Permalink
fix: custom permalink structures break pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-jw committed Oct 24, 2023
1 parent 593840a commit fda4aa5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/php/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$context['title'] = single_tag_title( '', false );
} elseif ( is_category() ) {
$context['title'] = single_cat_title( '', false );
array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
array_unshift( $templates, 'archive-' . get_queried_object()->slug . '.twig' );
} elseif ( is_post_type_archive() ) {
$context['title'] = post_type_archive_title( '', false );
array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );
Expand Down
15 changes: 15 additions & 0 deletions src/php/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ function filter_password_protected_posts( $query ) {
return $query;
}
add_filter( 'pre_get_posts', 'filter_password_protected_posts' );

/**
* Normalize queries for paginated archive pages to support custom permalink structures.
*
* @param array $query_string - The incoming query string to be normalized.
*/
function normalize_pagination_query_strings( $query_string ) {
if ( isset( $query_string['name'] ) && 'page' === $query_string['name'] && isset( $query_string['page'] ) ) {
unset( $query_string['name'] );
$query_string['paged'] = $query_string['page'];
}

return $query_string;
}
add_filter( 'request', 'normalize_pagination_query_strings' );

0 comments on commit fda4aa5

Please sign in to comment.