0

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);
    $content=$post_content->post_content;

    return $content;
}

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

    $last_post = get_post_by_id(83);

    print_r($last_post);

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!

2

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);
    $content[]=$post_content->post_content;
}

return $content;
}

Cheers, phpbits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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