最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get posts by multiple ID's (query)

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 3

Did 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',
);
发布评论

评论列表(0)

  1. 暂无评论