banner image
Sedang Dalam Perbaikan

Problem with 2 Queries on 1 Page


I have 2 queries on 1 page and they're showing the same posts, but the second query is turning in different posts including the posts of the first query. I've rearranged the code and done everything I could to stop it from happening, but I don't know what's wrong. Does anyone know what I'm doing wrong? here is my code:
<div id="top" class="left"> <h1>Sticky Posts</h1> <?php $query = new WP_Query( array( 'post_in' => get_option( 'sticky_posts') ) ); ?> <?php if ( $query->have_posts() ) : ?> <!-- pagination here --> <!-- the loop --> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; ?> <!-- end of the loop --> <!-- pagination here --> <?php else: ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> <?php wp_reset_postdata(); ?> </div> <div id="top" class="right"> <?php // the query $the_query = new WP_Query( array( 'post_status' => 'future', 'post_type' => 'post', 'order' => 'DESC' ) ); ?> <?php if ( $the_query->have_posts() ) : ?> <!-- pagination here --> <!-- the loop --> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; ?> <!-- end of the loop --> <!-- pagination here --> <?php wp_reset_postdata(); ?> <?php else: ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?> </div>

it is: 'post__in' with two underline characters. http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters do you want to exclude the sticky posts from the second loop? http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters then add it to the second query:
$the_query = new WP_Query( array( 'post_status' => 'future', 'post_type' => 'post', 'order' => 'DESC', 'ignore_sticky_posts' => 1 ) ); ?>
Problem with 2 Queries on 1 Page Problem with 2 Queries on 1 Page Reviewed by MCH on May 25, 2014 Rating: 5

No comments:

Powered by Blogger.