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.
Thanks for your help!
** EDIT **
This code works:
$query = new WP_Query(array( 'p' => 42 ));
But this one don't:
$query = new WP_Query(array( 'post__in' => $post_ids, 'post_status' => 'publish', 'ignore_sticky_posts' => false, 'orderby' => 'post__in', 'posts_per_page' => 2 ));
Whatever I put in my array, it doesn't works even if it is a
$query displays all my posts.