Created
September 16, 2021 22:51
-
-
Save wplit/8548f32ca9e703fe62284cd23d5c1245 to your computer and use it in GitHub Desktop.
Working pagination for Repeaters & Easy Posts on static home pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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