• Hello,

    I’m using the plugin Ajax Load More to have a button “Load more” under the first 16 items of a custom post type (backstages). The issue I’m facing is:
    – I can’t display the first 16 items before displaying the button (I only have the button so far)
    – when hitting the load more button, it displays duplicate items (I have only 23 in total and I see more than 30 rows of two items).
    I have put the following query in the Repeater Template:

    <?php  query_posts('post_type=backstages');?>
        <div class="container">
          <div class="row">
            <?php while ( have_posts() ) : the_post();
              $photo = get_the_post_thumbnail();
              $titre = get_the_title();
              $link = get_field('link');
              $size = "full"; ?>
    
              <div class="vc_col-sm-6 rowbackstage">
                <?php echo $photo; ?>
                <p class="titrebackstage allbackstages"><?php if( $link ): ?><a class="backstageslink" target="_blank" href="<?php echo esc_url( $link ); ?>"><?php endif; ?><?php the_title(); ?></a></p>
              </div>
            <?php endwhile; ?>
          </div>
        </div>
    
     <?php wp_reset_query(); // resets the aletered query back to the original

    And here is my shortcode: [ajax_load_more container_type=”div” post_type=”backstages” posts_per_page=”6″ post_format=”standard” orderby=”menu_order” offset=”16″ pause=”true” scroll=”false” button_label=”Charger plus” button_loading_label=”Chargement…” button_done_label=”Toutes les images sont affichées”]

    I’m clearly missing something here but I don’t know what. Could you help me?

    Thanks a lot!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    @codettes

    I have put the following query in the Repeater Template:

    You would not run a query inside your Repeater Template. The query is handled by Ajax Load More.

    And here is my shortcode: [ajax_load_more container_type=”div” post_type=”backstages” posts_per_page=”6″ post_format=”standard” orderby=”menu_order” offset=”16″ pause=”true” scroll=”false” button_label=”Charger plus” button_loading_label=”Chargement…” button_done_label=”Toutes les images sont affichées”]

    Using offset=”16″ in your shortcode will skip the first 16 posts in a query and start at post 17 – assuming the order (ASC/DESC etc) is the same this would work.

    For your case, the Repeater Template should likely look like this:

    <?php
    	global $post;
    	$photo = get_the_post_thumbnail();
    	$titre = get_the_title();
    	$link = get_field('link');
    	$size = "full"; 
    ?>
    
    <div class="vc_col-sm-6 rowbackstage">
    	<?php echo $photo; ?>
    	<p class="titrebackstage allbackstages"><?php if( $link ): ?><a class="backstageslink" target="_blank" href="<?php echo esc_url( $link ); ?>"><?php endif; ?><?php the_title(); ?></a></p>
    </div>

    Let me know if this helps at all.

    Thread Starter codettes

    (@codettes)

    Hi @dcooney,

    Thank you for your quick reply! Well, it works but I still have several issues:
    – I’d like to have the first 16 items to be visible then display the “load more” button. (For now on, I just have the “load more” button, so we don’t know what will be “more” loaded ;). That is the reason why I was using a query + “offset 16”.
    How do I display few items first?
    Fyi, the order of the items is managed by a plugin so I can manually choose the order.

    – My items are displayed in two columns, but some items are alone on their row. Any idea what may cause that?

    Thank you!

    Plugin Author Darren Cooney

    (@dcooney)

    How do I display few items first?

    You would need the Preloaded add-on for this functionality. Ajax Load More does not run a server side query, it’s only ajax unless you use this add-on.

    My items are displayed in two columns, but some items are alone on their row. Any idea what may cause that?

    You likely need to set a transition_container_classes parameter to match your theme.
    If you share a link I can get that for you

    Thread Starter codettes

    (@codettes)

    Hi @dcooney,

    That would be great, thanks! But the website is still under maintenance because it is not yet live. Is there a way I can share access to it in a private conversation?
    The theme I use is Bridge from Qode.

    Thank you!

    Plugin Author Darren Cooney

    (@dcooney)

    Thread Starter codettes

    (@codettes)

    Hi @dcooney,

    Thank you very much for your help! I finally decided to use a different way to display my pictures and get a “load more” button (I use an option that my theme offers) and it works well.

    I don’t need help anymore.

    Thank you very much for your reactivity!

    Best regards

    Plugin Author Darren Cooney

    (@dcooney)

    @codettes All good. thanks!

    This seems to be a bug.

    Seems as if… If a user click the Loadmore too soon, or too fast, you will get duplicates….

    Ive tried to hook in some js to the loadmore button to fire 20 times On page load. And I got duplicates. Once I slow down the auto fires (js triggers with set Timeout function) a bit to 5-10 secs, no duplicates – but that is too slow…

    If would be nice to get a fix for this…

    • This reply was modified 3 years, 6 months ago by samjco.
    Plugin Author Darren Cooney

    (@dcooney)

    @samjco there is a flag in place to not allow posts to load while posts are already loading so no this is not a bug.

    Can you replicate on my site using any of the demos?

    Hey @dcooney Ive used this code that will trigger the loadmore every 2sec.
    Please see for yourself and tell me if you are getting the same results..

    jQuery(document).ready(function($) {
    var numClickVar = 10; //How many times to fire.
    var i = 0;
    
    //First Click to start
    $('button.alm-load-more-btn').click();  
        function clickme() {
            setTimeout(function() {
                if ( i < numClickVar ){
                    //Check if button loaded in yet
                    if( $('button.alm-load-more-btn').length )  
                    {
                        $('button.alm-load-more-btn').click();            
                    }else{
                        //Try again
                        clickme();
                    }
                };
            },2000);
        };
    
    //Check to see if loadmore has loaded something
    window.almComplete = function(alm){
        console.log(i + " Ajax Load More Complete!");
        ++i;
        clickme();
    }
    });

    The reason why I would need to auto trigger the button in the first place, was because I believe the TOC would not work properly if I preload 10 post

    • This reply was modified 3 years, 6 months ago by samjco.
    • This reply was modified 3 years, 6 months ago by samjco.
    Plugin Author Darren Cooney

    (@dcooney)

    @samjco ill look tomorrow. Next time please open your own ticket. This OP thread is is nothing like the issue you are saying you have.

    Whether its a human click as in @codettes or a auto robot click, there stills was an issue with duplicate posts loading in at times…

    Plugin Author Darren Cooney

    (@dcooney)

    No. @codettes issue was a previous query on the page before Ajax Load More.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Load more button returning duplicate items and not displaying first 16 items’ is closed to new replies.