• Resolved jsites

    (@jsites)


    I have a page using Ajax Load More to return posts in a custom post type. When multiple pages load, some posts are duplicated several times.

    Here is my page’s code:

    <?php /*
    Template Name: Client List Page
     */
    get_header(); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div id="content">
            <section id="mainContent">
            	<?php include('library/snippets/featured-image-space.php'); ?>
                <div id="mainContentHolder">
                	<div id="inner-content" class="wrap cf">
                        <?php include('library/snippets/parent-title.php'); ?>
                		<main id="main" class="m-all t-2of3 d-5of7 cf" role="main" itemscope itemprop="mainContentOfPage" itemtype="https://schema.org/Blog">
                            <div class="entry-content">
    							<?php include('library/snippets/page-title.php'); ?>
    							<div class="contentColumns">
                                	<?php the_content(); ?>
    							</div>
                            </div>
                		</main>
                	</div>
                </div>
            </section>
    		<?php include('library/snippets/flexblockLoader.php'); ?>
    		<section id="clientList">
    			<div class="wrap">
    				<?php if(get_field('qd_client_list_title')){ ?>
    					<h1><?php echo get_field('qd_client_list_title'); ?></h1>
    					<div class="shortHR redHR"></div>
    				<?php } ?>
    				<div id="clientFilters">
    					<?php $industries = get_terms('qd_client_industry');
    					if($industries){ ?>
    						<div class="clientFilterHolder">
    							<select id="industryFilter">
    								<option value="" disabled selected>Industry</option>
    								<option value="all">See all Industries</option>
    								<?php foreach($industries as $industry){
    									echo '<option value="'.$industry->slug.'">'.$industry->name.'</option>';
    								} ?>
    							</select>
    						</div>
    					<?php } ?>
    					<?php $functions = get_terms('qd_client_function');
    					if($functions){ ?>
    						<div class="clientFilterHolder">
    							<select id="functionFilter">
    								<option value="" disabled selected>Function</option>
    								<option value="all">See all Functions</option>
    								<?php foreach($functions as $function){
    									echo '<option value="'.$function->slug.'">'.$function->name.'</option>';
    								} ?>
    							</select>
    						</div>
    					<?php } ?>
    				</div>
    				<div id="clientList">
    					<?php echo do_shortcode('[ajax_load_more container_type="div" repeater="template_2" post_type="qd_client" posts_per_page="15" orderby="menu_order"]'); ?>
    				</div>
    			</div>
    		</section>
    		<?php include('library/snippets/footer-widget.php'); ?>
        </div>
    <?php endwhile; endif; ?>
    <?php get_footer(); ?>

    For easier viewing, here is the shortcode being used:

    [ajax_load_more container_type="div" repeater="template_2" post_type="qd_client" posts_per_page="15" orderby="menu_order"]

    The repeater template being used is this:

    <div class="singleClient">
    	<?php $thisLogo = get_field('qd_client_logo'); ?>
    	<img src="<?php echo $thisLogo['sizes']['client-logo']; ?>" alt="<?php echo $thisLogo['alt']; ?>" />
    </div>

    Any thoughts on what’s happening and how to fix it?

    • This topic was modified 6 years, 5 months ago by jsites.

    The page I need help with: [log in to see the link]

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

    (@dcooney)

    @jsites Try moving Ajax Load More outside of the existing loop.
    Let me know,

    Thread Starter jsites

    (@jsites)

    I switched the file to this, and it still has the same issue. Note that the include php call for clientList.php has the shortcode stuff. In the orignial post, i put that file’s content inside the main page’s code for ease of reading.

    <?php /*
    Template Name: Client List Page
     */
    get_header(); ?>
    
        <div id="content">
            <section id="mainContent">
            	<?php include('library/snippets/featured-image-space.php'); ?>
                <div id="mainContentHolder">
                    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                	<div id="inner-content" class="wrap cf">
                        <?php include('library/snippets/parent-title.php'); ?>
                		<main id="main" class="m-all t-2of3 d-5of7 cf" role="main" itemscope itemprop="mainContentOfPage" itemtype="https://schema.org/Blog">
                            <div class="entry-content">
    							<?php include('library/snippets/page-title.php'); ?>
    							<div class="contentColumns">
                                	<?php the_content(); ?>
    							</div>
                            </div>
                		</main>
                	</div>
                    <?php endwhile; endif; ?>
                </div>
            </section>
    		<?php include('library/snippets/flexblockLoader.php'); ?>
            <?php include('library/snippets/clientList.php'); ?>
    		<?php include('library/snippets/footer-widget.php'); ?>
        </div>
    
    <?php get_footer(); ?>
    Plugin Author Darren Cooney

    (@dcooney)

    Not sure, whats the repeater template?

    Thread Starter jsites

    (@jsites)

    It’s in the original post, but here it is again:

    <div class="singleClient">
    	<?php $thisLogo = get_field('qd_client_logo'); ?>
    	<img src="<?php echo $thisLogo['sizes']['client-logo']; ?>" alt="<?php echo $thisLogo['alt']; ?>" />
    </div>
    Plugin Author Darren Cooney

    (@dcooney)

    Thanks. ALM thinks you have 158 clients. Is this the correct total?

    If not, you likely have an issue with a loop somewhere.

    Thread Starter jsites

    (@jsites)

    There are 158 posts in that post type.

    Plugin Author Darren Cooney

    (@dcooney)

    Ok thanks. Sorry, im not sure… might be something to do with menu_order or the plugin using the manage to do the ordering.

    Thread Starter jsites

    (@jsites)

    Ok, I removed the orderby=”menu_order” from the shortcode, and now it’s not duplicating the content. So I may need to look into the plugin I’m using for that, Intuitive Custom Post Order, and see if there’s something there. I’ll report back when I have something.

    Thread Starter jsites

    (@jsites)

    Ok, so here’s what happened and how I fixed it.

    The custom post type, qd_client, had not been enabled as a sortable post type in the Intuitive Custom Post Order plugin’s settings. As soon as I checked the box to enable that post type for that plugin, everything in ALM started working perfectly.

    Thanks for helping me figure this out.

    Separate unrelated item, hoping you’ll be able to make some progress on that filtering question I emailed you about earlier this week. Once that’s resolved, all of the ALM functionality for this site will be buttoned up.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Ajax Load More returning Duplicate Items’ is closed to new replies.