function slug_get_voyage_cover_image($object, $field_name, $request) { $images = array(); //get images from feature image $cover_image = wp_get_attachment_image_src(get_post_thumbnail_id($object['id']), 'full'); if (!empty($cover_image)) { for ($i = 0; $i < count($cover_image); $i++) { if (strpos($cover_image[$i], 'http') === 0) { $images['feature_image'] = $cover_image[$i]; } } } else { $images['feature_image'] = false; } $gallery = array(); $images_list = get_post_meta($object['id'], 'gallery'); //get images from gallery if (!empty($images_list[0])) { foreach ($images_list as $img_id) { $img_url = wp_get_attachment_image_src($img_id, 'full')[0]; if (strpos($img_url, 'http') === 0) { $gallery[] = $img_url; } } $images['gallery'] = $gallery; } else { //get images from guanaima $terms = get_the_terms($object['id'], 'location'); if (!empty($terms)) { $location = array(); foreach ($terms as $term) { $row['taxonomy'] = 'location'; $row['term'] = $term->name; $location[] = $row; } $response = \Experiensa\Config\RequestMedia::get_media_request_api('media', $location); if (!empty($response)) { foreach ($response as $image) { if (strpos($image['full_size'], 'http') === 0) { $gallery[] = $image['full_size']; } } } } $images['gallery'] = $gallery; } return $images; }
public static function get_voyage_images($postID) { $images = array(); $gallery = get_post_meta($postID, 'gallery'); //Get images from Gallery meta field if (!empty($gallery) && !empty($gallery[0])) { $images['image_url'] = wp_get_attachment_url($gallery[0]); $images['thumbnail_url'] = wp_get_attachment_thumb_url($gallery[0]); $images['thumbnail_image'] = wp_get_attachment_image($gallery[0], 'thumbnail'); return $images; } else { //Get images from Post Feature Image $feature_image_id = get_post_thumbnail_id($postID); if ($feature_image_id) { $full_image = wp_get_attachment_image_src($feature_image_id, 'full'); for ($i = 0; $i < count($full_image); $i++) { if (strpos($full_image[$i], 'http') === 0) { $images['image_url'] = $full_image[$i]; break; } } $thumbnail_image = wp_get_attachment_image_src($feature_image_id); for ($i = 0; $i < count($thumbnail_image); $i++) { if (strpos($thumbnail_image[$i], 'http') === 0) { $images['thumbnail_url'] = $thumbnail_image[$i]; break; } } $images['thumbnail_image'] = wp_get_attachment_image($feature_image_id); } else { //Get images from Guanaima API $terms = get_the_terms($postID, 'location'); if (!empty($terms)) { $location = array(); foreach ($terms as $term) { $row['taxonomy'] = 'location'; $row['term'] = $term->name; $location[] = $row; } $response = RequestMedia::get_media_request_api('media', $location); if (!empty($response)) { foreach ($response as $image) { if (strpos($image['full_size'], 'http') === 0 && strpos($image['thumbnail_size'], 'http') === 0) { $images['image_url'] = $image['full_size']; $images['thumbnail_url'] = $image['thumbnail_size']; $images['thumbnail_image'] = "<img width=\"150\" height=\"150\" src=\"" . $image['thumbnail_size'] . "\" class=\"attachment-thumbnail size-thumbnail\">"; break; } } } } } return $images; } }