I have this loop which should only display the first 18 posts and hide the rest under the Load More button. The first 8 posts when I click Load More are always repeated.I stated in posts-per_page that the page had to have 18 posts each but how to exclude duplicates?
Any clue? I don’t get it…

                <div id="tabs1">
                    <?php
                    $i = 1;
                    $args = array('post_type' => 'Team',
                        'paged' => 1,
                        'posts_per_page' => '18');
                    $loop = new WP_Query($args);
                    $posts_count = $loop->post_count;
                    $max = $loop->max_num_pages;
                    echo '<div class="row">';
                    echo '<div class="left-column col-sm-6"></div>';
                    echo '<div class="right-column col-sm-6"></div>';
                    echo '</div>';
                    while ($loop->have_posts()) : $loop->the_post();
                    $paged = (get_query_var('posts_per_page')) ? 
get_query_var('posts_per_page') : 1;

                        if ($i % 2 == 0) {
                            echo '<div class="col-sm-12 team-item go-
right">';
                        } else {
                            echo '<div class="col-sm-12 team-item go-        
left">';
                        }
                        echo '<div class="team-img">';
                        the_post_thumbnail('team-post-image',     
 array('class' => 'team-image'));
                        echo '<div class="team-image-overlay"><h2>', 
 the_title(), '</h2>
                       <i class="icons-plus plus" aria-hidden="true">
 </i>
                        </div><i class="icons-minus minus" aria-
 hidden="true"></i>';
                        echo '</div>';
                        echo '<div class="content-team">';
                        echo '<h2 class="team-member-name">', 
 the_title(), '</h2>';
                        echo '<div class="team-content">', 
 the_content(), '';
                        echo '</div>';
                        echo '<div class="women-social">';
                        if (get_field('external_ink')) {
                            echo '<a href="', 
 the_field('external_ink'), '" target="_blank" class="ex-link"></a>';
                        }
                        if (get_field('woman_facebook_url')) {
                            echo '<a href="', 
 the_field('woman_facebook_url'), '" target="_blank" class="facebook">
 </a>';
                        }
                        if (get_field('woman_xing_url')) {
                            echo '<a href="', 
 the_field('woman_xing_url'), '" target="_blank" class="xing"></a>';
                        }
                        if (get_field('woman_linkedin_url')) {
                            echo '<a href="', 
 the_field('woman_linkedin_url'), '" target="_blank" class="linked">
 </a>';
                        }
                        if (get_field('woman_twitter_url')) {
                            echo '<a href="', 
 the_field('woman_twitter_url'), '" target="_blank" class="twitter">
 </a>';
                        }
                        echo '</div>';
                        echo '</div>';
                        echo '</div>';

                        $i++;
                    endwhile;
                    ?>
                    <?php

                    echo '<div id="loading" data-paged="2" data-
 posttype="Team" data-max-pages="' . $max . '"></div>';
                    wp_reset_postdata();
                    ?>


                </div>

                <div class="load-more-block">
                    <a id="load-more" class="load-more-1"></a>
                </div>

Read more here: PHP data-paged Repeats content – WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: