Aleš Sýkora / July 20, 2021 / 3 comments

Oxygen Repeater Pagination not working on homepage

Post summary: 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…

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:

  1. 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); 
?>
  1. 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 ;).

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

3 comments

Share Your Thoughts