Skip to content

Instantly share code, notes, and snippets.

@wplit
Created September 16, 2021 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wplit/8548f32ca9e703fe62284cd23d5c1245 to your computer and use it in GitHub Desktop.
Save wplit/8548f32ca9e703fe62284cd23d5c1245 to your computer and use it in GitHub Desktop.
Working pagination for Repeaters & Easy Posts on static home pages
add_action( 'pre_get_posts', 'wpdd_pagination_fix_static_homepage' );
/**
* Fix pagination issue for custom loops on static homepage.
*
* @param WP_Query $query The default query for the front page.
* @return WP_Query The default query with custom parameters added.
*/
function wpdd_pagination_fix_static_homepage( $query ) {
$front_page_id = get_option( 'page_on_front' );
$current_page_id = $query->get( 'page_id' );
$is_static_front_page = 'page' === get_option( 'show_on_front' );
if ( $is_static_front_page && $front_page_id == $current_page_id ) {
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
} else {
$paged = 1;
}
$paged = intval( $paged );
$query->set( 'paged', $paged );
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment