• Hi there,

    I’m trying to avoid duplicate posts… but once I hit “view more”, I get many duplicates… please help me ?? as I m not sure what I’m doing wrong, I set up the right offset and my code is below… I would appreciate your prompt response as I need to deliver this pretty soon. thanks

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <?php $i=0; $j = $wp_query->post_count; ?>
    <?php $post_ids = array(); /* stop repeating posts */
    $query = new WP_Query('cat=-1'); ?>
    <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
    $post_ids[] = get_the_ID(); /* stop repeating posts */ ?>
    <?php include( get_stylesheet_directory().'/postBoxLandscape.php'); ?>
    <!-- end article -->
    <?php if ( 0 == ++$i%3 && $i < $j ) { echo '</div></div><div class="col-sm-4"><div class="row">';} ?>
    <?php endwhile; ?>
    </div>
    </div>
    <!--- CLOSE GRID COLUMN SYSTEM FOR THE POST LOOPS --->
    
    <?php endif; ?>
    </div> <!-- end #main -->
    <div class="col-sm-12 clearfix">
    <?php if($post_ids){
    //Implode the posts and set a variable to pass to our exclude param.
    $postsNotIn = implode(",", $post_ids);
    }
    
    // this is the ajax loader more videos for the homepage - plugin ajax load
    echo do_shortcode( '[ajax_load_more post_type="post" post_format="video" category="videos" tag="videos" offset="9" posts_per_page="9" pause="true" scroll="false" button_label="Ver Mas Videos"]' );
    ?>

    https://www.ads-software.com/plugins/ajax-load-more/

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

    (@dcooney)

    I’d need to see a link to your project to be able to help.

    offsetting by 9 posts means Ajax Load More will skip the first nine posts.

    Thread Starter nigrinis

    (@nigrinis)

    Hi There, thanks for our prompt reply ?? yes, I first load 9 posts, and after I display the “load more” button. You can check it out here: https://chicapractica.com/

    Plugin Author Darren Cooney

    (@dcooney)

    RIght. The issue looks like the query above is not using the same ordering as the Ajax Load More query.

    First post in the regular query – https://cl.ly/image/1x2E0q2i0j2H
    First post in the ALM query – https://cl.ly/image/3V3K0h3T1z1x

    If you are offsetting the posts the query’s need to be identical.

    Thread Starter nigrinis

    (@nigrinis)

    sorry I don’t understand what you are telling me. could you please assist me with a solution or a different approach, as I’m still confuse of what’s going on or what is wrong. I would appreciate your prompt reply.

    Thread Starter nigrinis

    (@nigrinis)

    its just a css look and feel change… If I se the same, it wont change anything… you can check it out again if you want and you will see the problem is still there. Im using the same query, just different CSS. However, I just changed the css to show you that the issue is still there.

    Thread Starter nigrinis

    (@nigrinis)

    this is the query Im using in the ALM template:

    <div class=”col-sm-4″>
    <div class=”row”>
    <?php include( get_stylesheet_directory().’/postBox.php’); ?>
    <?php if ( 0 == ++$i%3 && $i < $j ) { echo ‘</div>
    <div class=”row”>’;} ?>
    </div>
    </div>

    its the same as the regular I posted above… just without some wrapping divs. And I get the same result: https://chicapractica.com

    Plugin Author Darren Cooney

    (@dcooney)

    No, Im saying the query in use above Ajax Load More is not the same query as the one used in Ajax Load More. So the ‘offset’ will not work in this case. Both queries need to be identical and then you will offset Ajax Load More by ‘n’ number of posts.

    Thread Starter nigrinis

    (@nigrinis)

    hi yes, I have pasted the exact query (without the “postsNotIn”) and it’s still repeating… please have a look at my website again.

    her eis the code I placed in the ALM template:

    <div class=”col-sm-4″>
    <div class=”row”>
    <?php $i=0; $j = $wp_query->post_count; ?>
    <?php
    $query = new WP_Query(‘cat=4’); ?>
    <?php
    if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
    ?>
    <?php include( get_stylesheet_directory().’/postBox.php’); ?>
    <!– end article –>

    <?php if ( 0 == ++$i%3 && $i < $j ) { echo ‘</div></div><div class=”col-sm-4″><div class=”row”>’;} ?>

    <?php endwhile; ?>

    </div>
    </div>
    <!— CLOSE GRID COLUMN SYSTEM FOR THE POST LOOPS —>

    <?php endif; ?>

    Plugin Author Darren Cooney

    (@dcooney)

    Ok so now you have an even bigger issue.
    This must be something in your repeater template.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘displaying duplicate posts.’ is closed to new replies.