• Resolved marissalerer

    (@marissalerer)


    I’m creating a comma separated list of ids to load in with the plugin. I just installed the preload plugin and I’m getting some of the items duplicated. It seems pretty random.

    <?php
     $works = get_field('work');
     $workids = "";
     foreach ($works as $work) {
      $workids .= $work->ID.", ";
     }
    ?>
    <?php echo do_shortcode('[ajax_load_more preloaded="true" preloaded_amount="4" post_type="work" post__in="'.$workids.'" button_label="Load More" orderby="post__in" transition="fade" 	]'); ?>

    Am I implementing the plugin incorrectly?

    https://wordpress.org/plugins/ajax-load-more/

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

    (@dcooney)

    Hi Marissa,
    Could be a few reasons.

    1. An issue with your repeater template (Can you post it?)
    2. Looks like you have a trailing comma in your array? You need to remove that
    3. Can you orderby post__in ? I don’t think so, but I could be wrong.

    Cheers,

    Thread Starter marissalerer

    (@marissalerer)

    My template is a bit convoluted but here it is. I don’t think the trailing comma is the issue but I can certainly remove it.

    I’m using advanced custom fields for the ordering so I’ll look into other ordering options.

    <?php
    if (empty($post->post_password)){ ?>
    <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    	<?php
    	if(!is_home()){
    		if(get_field('project_image_override')){
    			$src = get_field('project_image_override');
    		}else{
    			$vid = get_field('featured_video_id');
    			$src = get_vimeo_thumb($vid, 'thumbnail_', '1200x420');
    		}
    	}else{
    		// if it's homepage serve the larger image
    		if(get_field('hero_image')){
    	      $src = get_field('hero_image');
    	  }else{
    	      $vid = get_field('featured_video_id');
    	      //$src = get_vimeo_thumb($vid, 'thumbnail_', '1200x710');
    	      $src = get_vimeo_thumb($vid, 'thumbnail_', '1200x675');
    	  }
    	}
    
    	?>
    
    	<img src="<?php echo $src; ?>" height="420" width="1200">
    
    	<header class="entry-header">
    			<div class="copy">
    			<?php $taxes = wp_get_post_terms(get_the_ID(), 'clients', array("fields" => "all"));
              $clients = '';
              foreach ($taxes as $tax) {
                  $clients.= $tax->name.', ';
              }
              $client = substr($clients, 0, -2);
    				?>
    			<h1 class="hasicon"><i class="ce-cross pink"></i><?php echo $client; ?></h1>
    			<?php the_title(); ?>
    			</div>
    	</header><!-- .entry-header -->
    	<a href="<?php the_permalink(); ?>"></a>
    </li><!-- #post-## -->
    <?php } ?>
    Plugin Author Darren Cooney

    (@dcooney)

    Ok, looking at your template I think it is it the issue.

    For testing, can you remove the php conditional?
    As stated on the Repeater Templates page:

    Tips and Tricks

    Always open and close your templates with an HTML element. In some rare cases data may not be displayed if not wrapped in HTML.
    e.g. <li> </li> or <div> </div>

    Thread Starter marissalerer

    (@marissalerer)

    I stripped it down to this:

    <li>
    	<img src="http://placehold.it/1200x420" height="420" width="1200">
    	<header class="entry-header">
    			<?php the_title(); ?>
    	</header><!-- .entry-header -->
    	<a href="<?php the_permalink(); ?>"></a>
    </li><!-- #post-## -->

    and I’m still getting the duplication.

    I actually stripped it down to just titles:

    Artist to Watch | Ty Dolla $ign
    Architect of the Future | Brand Film
    Underworld, Inc | New Season Launch
    Devious Maids | Custom Integration
    Artist to Watch | Benjamin Booker
    Devious Maids | Custom Integration
    Underworld, Inc | New Season Launch
    Dreamworks’ Home | Intergalactic Interview
    Consistently Amazing | Keynote Address
    Artist To Watch | Sam Smith
    Blaze | Commerical
    Halo Awards | Show Campaign
    Laugh Your Butt Off | Brand Image Refresh
    Team Umizoomi | App Spot

    and you can see what I mean about random duplication

    Plugin Author Darren Cooney

    (@dcooney)

    Ok,
    Can you fix the trailing comma and the orderby parameter?

    Other than that I’m not sure without having access to your site.

    Cheers,

    Thread Starter marissalerer

    (@marissalerer)

    according to the codex you can do post__in
    http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
    ‘post__in’ – Preserve post ID order given in the post__in array (available since Version 3.5)

    I have removed the trailing comma. Still no luck.

    Plugin Author Darren Cooney

    (@dcooney)

    Interesting!
    But I still think that wont work because of the way the plugin build the wp_query in the background.
    WP will likely require array(‘id’, ‘id’, ‘id’);

    Anyways, can you give me access?
    If so, you can use the contact form on the website.

    Thread Starter marissalerer

    (@marissalerer)

    somehow I got it to work. I changed what was being returned to just the ID since that’s all I needed anyway. Also that remove_all_filters seemed to help as well.

    <?php
    	$works = get_field('work');
    	$allwork = implode(",", $works);
    	remove_all_filters('posts_orderby');
    ?>
    	<?php echo do_shortcode('[ajax_load_more preloaded="true" post_type="work" post__in="'.$allwork.'" button_label="Load More" orderby="post__in" transition="fade"]'); ?>
    Plugin Author Darren Cooney

    (@dcooney)

    Excellent! Good work!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Preloaded Posts Showing up twice’ is closed to new replies.