Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress get multiple posts by id

Tags:

php

wordpress

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?

like image 629
RIK Avatar asked Dec 07 '11 23:12

RIK


1 Answers

$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.

like image 168
postpostmodern Avatar answered Oct 17 '22 05:10

postpostmodern