Robin Knight Robin Knight - 2 months ago 32
PHP Question

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?

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

Be sure to check out http://codex.wordpress.org/Class_Reference/WP_Query as well, the section Interacting with WP_Query will be very valuable to you.

Comments