1

I need to pass many ids to the parameter post__in in args. This not work !!! Help me please.

foreach ($rows as $obj) {

    $todos .= $obj->ID . ",";

}

$ids = trim(trim($todos), ","); # echo $ids output -------> 613,647

$args = array (
     'post_type' => 'professores',
     'post__in'  => array($ids)    <----- Don't work
);

How to do this work?

Thanks!

2

Don't concatenate your id values into a comma separate string otherwise you will have to explode() by comma delimiter which is pointless, instead, if you are getting IDs from some other business logic as evidenced in your iteration over $rows, then build an array of IDs as per the following example:

$ids = array();

foreach ($rows as $obj) {
    $ids[] = $obj->ID;
}

$args = array (
     'post_type' => 'professores',
     'post__in'  => $ids
);

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.