How do I get post content if I have an array of id's. Basically, I have a function that get post content if you provide an ID. but it doesn't work if I have an array of id's. My function is:

function get_post_by_id($id){
    $post_content = get_post($id);

    return $content;

Now if I pass an id to this function it will work. For example:

    $last_post = get_post_by_id(83);


How do I get post_content if I have an array of ID's.Something like:

$last_post = get_post_by_id(array(83,80,92));

It doesn't work this way now. Please help!

1 Answer 1


If your first query works you can try something like this :

function get_post_by_id($id){
$content = array();
foreach ($id as $key => $value) {
    $post_content = get_post($value);

return $content;

Cheers, phpbits

  • No problem :). Happy to help. Commented Apr 8, 2014 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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