Author is Aleš Sýkora
Updated: 9. 2. 2022, Added: 20. 7. 2021
Oxygen Repeater Pagination not working on homepage
When you use repeater on static front-page of your WordPress site and you also wants to use pagination - it doesn't work at all. It stops at /page/2 and never display /page/3. It still repeat the second page.
However - it looks like Oxygen bug, but it is not. As you can see: https://codex.wordpress.org/Pagination#static_front_page.
To correct this problem, I have found a different ways:
- Official WordPress CODEX way - not working with repeater for me. Add a Code Block to front page and use this code. You will propably need to create the whole query in code block then:
<?php
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
query_posts('posts_per_page=9&paged=' . $paged);
?>
- pre_get_posts way found on Yankiara's GitHub Thanks! You need to use two code blocks. First before your repeater element and second one after.
<?php
/*
* Put following code BEFORE running the query (WP loop, Oxygen's repeater, etc.)
* What it does:
* - updates query with right page number variable to display the correct page
* - assigns the query to wp_query so that pagination links work
*/
function handle_pagination_on_frontpage( $query ) {
global $wp_query;
if ( !is_admin() && is_front_page() && $query->query['post_type'][0] == 'chage-to-your-post-type' ) {
$paged = get_query_var( 'page' );
$query->set( 'paged', $paged ? $paged : 1 );
$wp_query = $query;
}
}
add_action( 'pre_get_posts', 'handle_pagination_on_frontpage' );
?>
Second after your repeater element:
<?php
/*
* Put following code AFTER the query
*/
remove_action( 'pre_get_posts', 'handle_pagination_on_frontpage' );
?>
This one works well for me. Do not forget to change the post type slug ;).
Great work.
Thanks
A.Hannan
Don't use post per page in repeater instead use the post per page option in WordPress setting > reading.
It depends on situation and your needs.