How to extract all ID variables from a query string?

$string will contain a comma separated list of IDs:

$ids = array();
foreach( $array as $post ) {
    if( !in_array( $post->ID, $ids ) ) {
        $ids[] = $post->ID;
    }
}

$string = implode( ', ', $ids );

Note: This uses basically no wordpress, other than the post object…which is really just an object.

Leave a Comment