admin管理员组文章数量:1316336
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',
);
本文标签: Get posts by multiple ID39s (query)
版权声明:本文标题:Get posts by multiple ID's (query) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741985608a2408657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论