Aleš Sýkora wrote

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:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Use global colours from Oxygen Builder in CSS
You have defined your Global colors in Oxygen Builder and now you need use them in CSS styles? No Problem! You can use your global colors within CSS styles. Just open Settings > Global Styles > Colors, click on your colour group and you will see your colors with assigned ID’s to each of them. […]
Read More
Aleš Sýkora wrote
Get homepage link as a logo link in Oxygen Builder
Wrap your website’s logo in link wrapper and use this PHP function inside, to create the Home link.
Read More
Aleš Sýkora wrote
Basic SEO plugin with Toolset Types & Types Fields API
29. 9. 2018 in
Make your own SEO plugin with Toolset Types. No need to install any additional SEO plugins. Read our tutorial and make your own today!
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram