重复的帖子,而使用无限滚动+随机顺序



我使用无限滚动的wp_query来显示特定cpt存档页面中的帖子。当我将"order"设置为"date"时,一切正常,但是当我将其更改为"rand"时,查询返回正确的帖子数量,但其中一些是重复的。

这是我使用的代码:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$loopb = new WP_Query( array( 'post_type' => 'my_post_type', 'posts_per_page' => 10, 'paged' => $paged, 'order' => 'rand' ) ); 
$value = get_field('thumbnail_sizing');
 ?>
<?php while ( $loopb->have_posts() ) : $loopb->the_post(); 
    $thumb_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'small-size' );
$full_img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full-size' );
$thumb_img_ratio = 70; 
if (isset($thumb_img[1]) && isset($thumb_img[2]) && $thumb_img[1] > 0) {
    $thumb_img_ratio = $thumb_img[2] * 100/$thumb_img[1];
} ?>

<div class="mosaic">
    <a href="#" class="grayscale">
        <div class="mosaic__image" style="padding-top: <?php echo $thumb_img_ratio;?>%;">
            <img src="<?php echo $thumb_img[0]; ?>" data-src="<?php echo $full_img[0]; ?>" alt="<?php the_title();?>">
        </div>
        <div class="meta">
            <div class="flex">
                <div class="flex_item">
                    <h2 class="meta_title"><?php the_field('name1');?> <span class="divider">&amp;</span> <?php the_field('name2');?></h2>
                    <hr class="separator">
                    <span class="cat">view image</span> 
                </div>
            </div>
        </div>
    </a>
</div>

<?php endwhile; ?>

随身携带随机种子,我不知道WP_Query是否支持它,但它将是RANDOM(SEED)(例如RANDOM(1234))在直接mysql

最新更新