Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a string with post ID's: 43,23,65.
I was hoping I could use get_posts() and use the string with ID's as an argument.

But I can't find any functions for retrieving multiple posts by ID.

Do I really have to do a WP_query?

I've also seen someone mention using tag_in - but I can't find any documentation on this.

share|improve this question
    
have you tried to use the 'include' argument of get_posts() codex.wordpress.org/Template_Tags/get_posts ? –  Michael Dec 31 '11 at 11:56
add comment

1 Answer 1

up vote 4 down vote accepted

You can use get_posts as it takes the same arguments as WP_Query.

To pass it the IDs, use 'post__in' => array(43,23,65); (only takes arrays). Something like:

$args = array(
    'post__in' => array(43,23,65);
);

$posts = get_posts($args);

foreach ($posts as $p) :
    //post!
endforeach;

I'd also set the post_type and posts_per_page just for good measure.

share|improve this answer
    
Ah, thanks. I'll test this. Happy New Year :) –  Steven Dec 31 '11 at 12:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.