Repeat WP Query loop twice

Viewed 10

I have a related posts slider but currently there is not enough posts to actually slide. The design is such that it's not a simple case of displaying the posts but not sliding them until there is more.

As a short term solution, I am trying to find a way to loop through the posts twice to give the appearance of an infinite loop.

I am using slick slider and initially tried the settings:

infinite: true,
loop: true

but I can't get it to work even though apparently that should do the trick.

I am now trying to just pull through the posts twice

I have tried adjusting the count to things like

$count+1;
$count = 2
$count+=5;

All sorts of variations but I think I am way off base.

I would appreciate any help or a point in the right documentation. I have been reading about iterations but I can't grasp how they would be included in this as I had help with this from another developer.

<div class="log-book-carousel">
            
                        <?php
                        
                        $current_page_id = get_the_ID();
                        $args = [
                            'posts_per_page'    => '6',
                            'post__not_in'      => [$current_page_id]
                        ];
                        $the_query = new WP_Query( $args ); ?>
                                 
                                <?php 
                                // Start our WP Query
                                while ($the_query -> have_posts()) : $the_query -> the_post(); 
                                // Display the Post Title with Hyperlink
                                ?>
            
                                <div class="slides match-height">
                                    
                                    <a href="<?php the_permalink(); ?>" title="Read more of the blog post '<?php the_title_attribute(); ?>'">
            
                                                <?php if (has_post_thumbnail()) : ?>
                        
                                                    <div class="log-book-slider-image">
                                                            <?php the_post_thumbnail(); ?>
                                                    </div>
                        
                                                <?php endif; ?>
                        
                                                <div class="log-book-details-wrapper white-bg">
                        
                                                    <h3 class="black log-title"><?php the_title(); ?></h3>
                        
                        
                                                    <div class="log-book-slider-excerpt ">
                                                        <p class="log-book-text"><?php sew_display_post_intro_block( $post->ID, 10 ); ?></p>
                                                    </div>
                        
                                            
                                                </div>
                                    </a>    
                                </div>
            
                                <?php
                                $count++;
                                endwhile;
            
                            wp_reset_postdata(); 
                            ?>
                        
            
                    </div>
                    
0 Answers
Related