Multiple Loops and Duplicate Issues
-
WP_Query:
<?php $popular_loop = new WP_Query( array('v_sortby' => 'views', 'posts_per_page' => '4')); if( $popular_loop->have_posts() ): while( $popular_loop->have_posts() ): $popular_loop->the_post(); $do_not_duplicate[] = $post->ID ?> <li> <a href="<?php the_permalink() ?>" target="_blank" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> <h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" target="_blank"><?php $thetitle = $post->post_title;$getlength = mb_strlen($thetitle);$thelength = 19;echo substr($thetitle, 0, $thelength);if ($getlength > $thelength) echo "..."; ?></a></h3> <p><?php echo get_post_meta($post->ID,'Resumo',true); ?></p> </li> <?php endwhile; endif; wp_reset_postdata(); ?>
Main Loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); if (in_array($post->ID, $do_not_duplicate)) continue; ?> <li><a href="<?php the_permalink() ?>" target="_blank" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a> <h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" target="_blank"><?php $thetitle = $post->post_title;$getlength = mb_strlen($thetitle);$thelength = 19;echo substr($thetitle, 0, $thelength);if ($getlength > $thelength) echo "..."; ?></a></h3> <p><?php echo get_post_meta($post->ID,'Resumo',true); ?></p></li> <?php endwhile; endif ?>
What i want is to show the main loop with 20 posts (i’ve set in general settings to show only 20 posts) and a second wp_query with 4 posts. The main loop needs to exclude the posts from the wp_query and it’s working. The only problem i have here is that the main loop is missing 1 post. It only shows 19 posts instead of 20. This website only have 24 posts for testing purposes. Any ideas why it shows minus 1 post ?
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Multiple Loops and Duplicate Issues’ is closed to new replies.