post__in doesn't work in custom Page template
-
Hi,
I have a problem with a loop that I try to put into a custom Page template. I would like to display posts with conditions, but whatever I put in my WP_query parameters, it is not taking in consideration.
Here is all my template code:
<?php /* Template Name: Trends */ get_header(); ?> <section id="top"> <?php the_post(); ?> <div class="intro"><?= get_the_title(); ?></div> <?php the_content();?> <?php $args = array( 'posts_per_page' => 2 ); $latest = new WP_Query( $args ); ?> <?php while( $latest->have_posts() ) : $latest->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; wp_reset_postdata(); ?> </section> <?php get_footer(); ?>This code gives me all my posts, and not only the 2 I asked on args. But whatever I put it always gives me the default loop…
I’ve tried everything and I still don’t understand.
If notice that this works:
$query = new WP_Query(array( 'p' => 42 ));But if I use something else in my WP_Query like that:
$query = new WP_Query(array( 'post__in' => array(42,55,34), 'post_status' => 'publish', 'ignore_sticky_posts' => false, 'orderby' => 'post__in', 'posts_per_page' => 2 ));It always display all my posts.
Thanks for your help!
The topic ‘post__in doesn't work in custom Page template’ is closed to new replies.