fields(‘n’)->condition(‘status’, 1)->condition(“type”,”gallery”, ‘=’)->execute();
$allGalleryArray =array();
$allGalleryVideoArray =array();
foreach ($result as $record) {
if(in_array($record->nid, $galleryNodeIds)){
$node = node_load($record->nid);
$galleryImages = array();
foreach($node->field_images[‘und’] as $image){
$galleryImages[] = array(‘url’ => file_create_url($image[‘uri’]), ‘alt’ => $image[‘alt’], ‘title’ => $image[‘title’]);
}
$allGalleryArray[] = array(
‘id’ => $node ->vid,
‘title’ => $node->field_title[‘und’][0][‘value’],
‘videoUrl’ => $node->field_video[‘und’][0][‘video_url’],
‘position’ => (int)$node->field_position[‘und’][0][‘value’],
‘gallery’ => $galleryImages
);
if($node->field_video[‘und’][0][‘video_url’] != ” && $node->field_video[‘und’][0][‘video_url’] != null){
$allGalleryVideoArray[] = array(
‘id’ => $node ->vid,
‘title’ => $node->field_title[‘und’][0][‘value’],
‘videoUrl’ => $node->field_video[‘und’][0][‘video_url’],
‘position’ => (int)$node->field_position[‘und’][0][‘value’],
);
}
}
}
//print_r($allGalleryArray)
usort($allGalleryArray, function($a, $b) {
return $a[‘position’] – $b[‘position’];
});
usort($allGalleryVideoArray, function($a, $b) {
return $a[‘position’] – $b[‘position’];
});
?>