public function __construct($posts = array(), $post_class = '\\Timber\\Post')
{
$returned_posts = array();
if (is_null($posts)) {
$posts = array();
}
foreach ($posts as $post_object) {
$post_class_use = $post_class;
if (is_array($post_class)) {
$post_type = get_post_type($post_object);
$post_class_use = '\\Timber\\Post';
if (isset($post_class[$post_type])) {
$post_class_use = $post_class[$post_type];
} else {
if (is_array($post_class)) {
Helper::error_log($post_type . ' of ' . $post_object->ID . ' not found in ' . print_r($post_class, true));
} else {
Helper::error_log($post_type . ' not found in ' . $post_class);
}
}
}
// Don't create yet another object if $post_object is already of the right type
if (is_a($post_object, $post_class_use)) {
$post = $post_object;
} else {
$post = new $post_class_use($post_object);
}
if (isset($post->ID)) {
$returned_posts[] = $post;
}
}
$returned_posts = self::maybe_set_preview($returned_posts);
parent::__construct($returned_posts, $flags = 0, 'Timber\\PostsIterator');
}