I try to get multiple post by ID. For this I created an array for p but I get only the post for the first ID.
<?php
$args = array(
'p' => array('206', '189'),
'post_type' => array( 'product' ),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
}
?>
I try to get multiple post by ID. For this I created an array for p but I get only the post for the first ID.
<?php
$args = array(
'p' => array('206', '189'),
'post_type' => array( 'product' ),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
}
?>
Share
Improve this question
asked Nov 18, 2020 at 0:21
BryanBryan
111 bronze badge
1 Answer
Reset to default 3Did you look at the documentation for WP_Query?
The p
parameter takes only a single integer.
Use post__in
.
$args = array(
'post__in' => array( 206, 189 ),
'post_type' => 'product',
);