• I have to loop through my posts on two pages, one of which in the Main page. On the other page it is working well, but on the main page it always loads the same posts that are present on page load. I even made the code on the main page the same as on the page, where it woks, but still no result.
    Please, help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • but on the main page it always loads the same posts that are present on page load.

    Same issue here.

    Plugin Author Idiom

    (@brianbrey)

    Hi,

    Do you know if there are any actions or functions in a plugin or in the template that might be changing the main loop on that page? Particularly something that might affect the ‘paged’ query var?

    The plugin works by requesting the current page, appending the paged query var to the url, then appending the results to the current page’s html.

    For example if you added the load more button on “yoursite.com/home”, the plugin will make a request to “yoursite/home/?paged=2” when you click the load more button. If there is something in your WordPress theme or a plugin that is changing or affecting the paged query var or any query vars it will cause the plugin to possibly load incorrect data.

    I hope that helps possibly narrow down the reason for the bug. With more details on your particular environment, I can try and give a more specific answer. I know how frustrating it can be when something works on one page and not another.

    Thanks for downloading!

    Hi,

    I run no other plugins on my dev environment. The theme is a one-page theme, so just one frontpage.

    1. I have homepage set to a static page (not the posts page)
    2. The page code section for easy load more looks like this: https://pastebin.com/raw/nBrSrh48

    When I press load more, it loads the same 6 posts again, and again.

    Plugin Author Idiom

    (@brianbrey)

    Thanks Alexander for that code snippet. I believe I know what the issue is. In your template you are creating a new WP_Query, and this new query isn’t using the paged query var passed by the plugin. By modifying your query you can get this to work however.

    
    
    <div id="ajax">	
    									
    <?php 
      // Get the 'paged' query var
      $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
      $args = array(
        'posts_per_page' => 6,
        'paged' => $paged,
        'ignore_sticky_posts' => 1
      );
    
      $the_query = new WP_Query( $args );
    
    ?>
    
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    								
    <?php the_title(); ?>
    								
    <?php endwhile; ?>
    										
    </div><!--/#ajax-->
    
    <?php load_more_button(); ?> 
    <?php wp_reset_postdata(); ?>
    
    • This reply was modified 7 years, 3 months ago by Idiom.

    Hi,

    Thanks for your help – however, the same issue remains with your code: https://i.imgur.com/cStC4mf.png (loaded same over and over). No idea why it does that.

    Plugin Author Idiom

    (@brianbrey)

    Hi Alex,

    Sorry you are still have trouble with the plugin. Perhaps are there any other plugins or something within your theme that may be filtering the query vars?

    For example, something using the query_vars filter could potentially be removing or altering the ‘paged’ variable.

    If you haven’t tried already, deactivating plugins one at a time and testing the page might reveal if there is a conflict.

    Or if you don’t mind sending more of your main page template code. I can look to see if there is something else in the template that might be preventing the load more button from working.

    Thanks for your patience as we figure this bug out!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Not working correctly on the Main page’ is closed to new replies.