简体   繁体   中英

Wordpress get multiple posts by id

I need to get multiple posts in wordpress by ID.

get_posts('p=34,36');

I assumed that that might work, but it only gives the first post.

I tried then to use an array:

$args = array( 'p' => array(34,36));

That delivered no results.

get_posts('p=34+36'); NO and get_posts('p=34&p=36'); Last one only

Any ideas?

$args = array( 'post__in' => array(34,36) );

请务必查看http://codex.wordpress.org/Class_Reference/WP_Query与WP_Query交互的部分对您非常有价值。

$args = array( 
           'post_type' => 'page', // must
           'post__in' => array(34,36) 
        );
$posts = get_posts($args);
print_r($posts);

this may help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM