Support » Plugin: WordPress Infinite Scroll - Ajax Load More » Duplicate Post Issue

  • Dear Author,
    I am using ALM plugin and its giving me duplicate post issue. Please check the repeater template code below –

    <article class=”post large”>
    <div class=”article_img”>
    <?php if ( has_post_thumbnail() ) { ?>
    ” title=”<?php the_title_attribute(); ?>”>
    <?php the_post_thumbnail(‘large-post-thumb’); ?>

    <?php }else{?>
    “>
    <?php } ?>
    </div>
    <div class=”article_content”>
    <div class=”inner_wrap”>
    <h3 class=”entry-title”>“>
    <?php the_title(); ?>
    </h3>
    <?php $content = get_the_content();
    // $trimmed_content = wp_trim_words($content, 20, ‘…’);
    // echo ‘<p>’.$trimmed_content.'</p>’;
    ?>
    <div class=”meta”> <span class=”publish_date”><i class=”fa fa-calendar-minus-o”></i><?php echo get_the_date();?></span> | <span class=”categories”>in:
    <?php the_category( ‘ ‘ ); ?>
    </span> | <span class=”post_comment”><i class=”fa fa-comment” aria-hidden=”true”></i>
    <?php comments_number( ‘no Comment(s)’, ‘1 Comment’, ‘% Comment(s)’ ); ?>
    </span> | <span class=”views”><i class=”fa fa-eye” aria-hidden=”true”></i><?php if(function_exists(‘the_views’)) { the_views(); }?> Views</span> </div>
    </div>
    </div>
    </article>

    and check my theme code below –

    $args = array(
    ‘post_type’ => ‘post’,
    ‘post_format’ => ‘standard’,
    ‘cat’ => get_cat_name(get_field(‘first_category’)),
    ‘posts_per_page’ => 9,
    ‘orderby’ => ‘date’,
    ‘order’ => ‘DESC’,
    );
    $wp_query = new WP_Query($args);

    Please check the ALM shortcode below –
    [ajax_load_more post_type=”post” post_format=”standard” category=”‘.get_cat_name(get_field(‘first_category’)).'” offset=”9″ posts_per_page=”9″ transition=”none” max_pages=”0″ container_type=”div” orderby=”date” order=”DESC”]

    I am not sure where I am doing wrong. Can you please check and confirm

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author dcooney

    (@dcooney)

    Hi webrndexperts,
    Your code is malformed in your post – Is there anyway you can post this again and format your code in a code block?

    <article class=”post large”>
    <div class=”article_img”>
    <?php if ( has_post_thumbnail() ) { ?>
    ” title=”<?php the_title_attribute(); ?>”>
    <?php the_post_thumbnail(‘large-post-thumb’); ?>

    <?php }else{?>
    “>
    <?php } ?>
    </div>
    <div class=”article_content”>
    <div class=”inner_wrap”>
    <h3 class=”entry-title”>“>
    <?php the_title(); ?>
    </h3>
    <?php $content = get_the_content();
    // $trimmed_content = wp_trim_words($content, 20, ‘…’);
    // echo ‘<p>’.$trimmed_content.'</p>’;
    ?>
    <div class=”meta”> <span class=”publish_date”><i class=”fa fa-calendar-minus-o”></i><?php echo get_the_date();?></span> | <span class=”categories”>in:
    <?php the_category( ‘ ‘ ); ?>
    </span> | <span class=”post_comment”><i class=”fa fa-comment” aria-hidden=”true”></i>
    <?php comments_number( ‘no Comment(s)’, ‘1 Comment’, ‘% Comment(s)’ ); ?>
    </span> | <span class=”views”><i class=”fa fa-eye” aria-hidden=”true”></i><?php if(function_exists(‘the_views’)) { the_views(); }?> Views</span> </div>
    </div>
    </div>
    </article>

    and check my theme code below –

    $args = array(
    ‘post_type’ => ‘post’,
    ‘post_format’ => ‘standard’,
    ‘cat’ => get_cat_name(get_field(‘first_category’)),
    ‘posts_per_page’ => 9,
    ‘orderby’ => ‘date’,
    ‘order’ => ‘DESC’,
    );
    $wp_query = new WP_Query($args);

    Please check the ALM shortcode below –

    [ajax_load_more post_type=”post” post_format=”standard” category=”‘.get_cat_name(get_field(‘first_category’)).'” offset=”9″ posts_per_page=”9″ transition=”none” max_pages=”0″ container_type=”div” orderby=”date” order=”DESC”]

    Please let me know if its ok now or not

    here is my website URL –
    http://congomikili.com/

    Plugin Author dcooney

    (@dcooney)

    I can’t tell where your posts are duplicating… Is Ajax Load More on the homepage?

    Are they duplicating in Ajax Load More? or are they duplicating the posts that are already on your page before ajax?

    Hi @dcooney,

    Even i am facing the same issue. ajax load more here is posting the duplicate posts that are already present on the page. Can you please help me fix this issue.

    I am attaching the link of the site where i am using ajax-load-more.

    http://yourdost.com/blog/category/stories

    Plugin Author dcooney

    (@dcooney)

    Hi @reddysridhar53,
    You will need to remove the query above Ajax Load More from your template OR use the offset parameter of Ajax Load More to offset the loading.

    Cheers,

    Hi Dcooney,

    Im experiencing the same problem.

    My code for posts is:

    <ul class="post_list">
        <?php
        $args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'posts_per_page' => '6',
        );
        $the_query = new WP_Query( $args );
    
        $i = 1;
        // The Loop
        if ( $the_query->have_posts() ) :
        while ( $the_query->have_posts() ) : $the_query->the_post();
          // Do Stuff
            $post_id = $post->ID;
    
            $author_id = $post->post_author;
            $author_name =  get_userdata($author_id)->display_name;
    
            $category_id = get_the_category($post_id);
            $category_name = $category_id[0]->name;
    
            $date_posted = get_the_date( '', $post_id );
    
        ?>
    
        <!-- Branding -->
    
        <?php if ($i%3==0) {
            if ( wp_is_mobile() ) {
                ?>
                <div class="banner_wide">
                    <a href="#">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/asus/320x50.jpg" alt="">
                    </a>
                    <a href="http://shop.lenovo.com/us/en/laptops/ideapad/y700-series/y700-15-inch/">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/lenovo/lenovo_320x50.jpg" alt="">
                    </a>
                    <a href="http://www.coolermaster.com/">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/cm_serbia/CM_Serbia_KGB_320x50_MasterKeys_Lite_combo_Black_17_12_2016.jpg" alt="">
                    </a>
                </div>
                <?php
            } else {
                ?>
                <div class="banner_wide">
                    <a href="http://www.monitor.rs/pretraga?search_api_views_fulltext=asus+z270">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/asus/680x90-001.jpg" alt="">
                    </a>
                    <a href="">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/lenovo/lenovo_680x90.jpg" alt="">
                    </a>
                </div>
                <?php
            }
        } ?>
    
        <li class="item">
            <a href="<?php the_permalink(); ?>" class="featured_image">
                <?php the_post_thumbnail('list_image');    ?>
            </a>
            <div class="post_content">
                <a href="<?php the_permalink(); ?>" class="post_title"><h2><?php the_title(); ?></h2></a>
                <h4><?php echo $date_posted; ?></h4>
                <?php the_excerpt(); ?>
            </div>
            <div class="post_info">
                <div class="category">
                    <?php echo $category_name; ?>
                </div>
            </div>
        </li>
    
        <?php
        $i++;
        endwhile;
        endif;
        // Reset Post Data
        wp_reset_postdata();
        ?>
    </ul>
    <?php
    echo do_shortcode( '[ajax_load_more container_type="ul" offset="6" css_classes="post_list" post_type="post" pause="true" button_label="LOAD MORE"]' );
    ?>
    

    My repeater template is:

        <?php
        $args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
        );
        $the_query = new WP_Query( $args );
    
        $i = 1;
        // The Loop
        if ( $the_query->have_posts() ) :
        while ( $the_query->have_posts() ) : $the_query->the_post();
          // Do Stuff
            $post_id = $post->ID;
    
            $author_id = $post->post_author;
            $author_name =  get_userdata($author_id)->display_name;
    
            $category_id = get_the_category($post_id);
            $category_name = $category_id[0]->name;
    
            $date_posted = get_the_date( '', $post_id );
    
        ?>
    
        <!-- Branding -->
    
        <?php if ($i%3==0) {
            if ( wp_is_mobile() ) {
                ?>
                <div class="banner_wide">
                    <a href="#">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/asus/320x50.jpg" alt="">
                    </a>
                    <a href="http://shop.lenovo.com/us/en/laptops/ideapad/y700-series/y700-15-inch/">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/lenovo/lenovo_320x50.jpg" alt="">
                    </a>
                    <a href="http://www.coolermaster.com/">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/cm_serbia/CM_Serbia_KGB_320x50_MasterKeys_Lite_combo_Black_17_12_2016.jpg" alt="">
                    </a>
                </div>
                <?php
            } else {
                ?>
                <div class="banner_wide">
                    <a href="http://www.monitor.rs/pretraga?search_api_views_fulltext=asus+z270">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/asus/680x90-001.jpg" alt="">
                    </a>
                    <a href="">
                        <img src="<?php echo get_template_directory_uri(); ?>/elements/branding/lenovo/lenovo_680x90.jpg" alt="">
                    </a>
                </div>
                <?php
            }
        } ?>
    
        <li class="item">
            <a href="<?php the_permalink(); ?>" class="featured_image">
                <?php the_post_thumbnail('list_image');    ?>
            </a>
            <div class="post_content">
                <a href="<?php the_permalink(); ?>" class="post_title"><h2><?php the_title(); ?></h2></a>
                <h4><?php echo $date_posted; ?></h4>
                <?php the_excerpt(); ?>
            </div>
            <div class="post_info">
                <div class="category">
                    <?php echo $category_name; ?>
                </div>
            </div>
        </li>
    
        <?php
        $i++;
        endwhile;
        endif;
        // Reset Post Data
        wp_reset_postdata();
        ?>
    

    well… just removed query and all works fine, but thank you anyway.

    Which query did you remove @st3f4ns?

    @stonecorleone, Removed query from repeater template, left only this part:

    <li class="item">
            <a href="<?php the_permalink(); ?>" class="featured_image">
                <?php the_post_thumbnail('list_image');    ?>
            </a>
            <div class="post_content">
                <a href="<?php the_permalink(); ?>" class="post_title"><h2><?php the_title(); ?></h2></a>
                <h4><?php echo $date_posted; ?></h4>
                <?php the_excerpt(); ?>
            </div>
            <div class="post_info">
                <div class="category">
                    <?php echo $category_name; ?>
                </div>
            </div>
        </li>
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Duplicate Post Issue’ is closed to new replies.