WP_Query returns post multiple times
-
Hi,
I googled for that problem and already used the search function, but I couldn’t find anyone with the same problem.
On my index.php i’m using two loops.
First:
<?php $not_again = array(); $args = array( 'numberposts' => 4, 'meta_key' => 'ratings_average', 'orderby' => 'meta_value_num', 'order' => 'DESC','category_name' => 'showcase', ); $postslist = get_posts( $args ); foreach ( $postslist as $post ) : setup_postdata( $post ); $not_again[]= $post->ID; ?>
Second:
<?php $args = array('posts_per_page' => -1, 'post__not_in' => $not_again, 'post_type' => 'post', 'orderby' => 'date', 'order' => 'DESC','category_name' => 'showcase'); $my_query = new WP_Query($args); if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
I’m saving the posts shown in the first loop IDs in the $not_again Array. Then i’m using that array with the post__not_in Option.
My problem: (example)
Loop 1 returns: 1 2 3 4
Loop 2 without category_name returns: 5 6 7 8
Loop 2 with category_name returns: 5 6 7 8 5 6 7 8Anyone ever expierenced that? Any ideas how to solve it?
Thank you in advance!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘WP_Query returns post multiple times’ is closed to new replies.