invp_get_the_photos( mixed $sizes, int|null $post_ID = null )
invp_get_the_photos
Parameters Parameters
- $sizes
-
(mixed) (Required)
- $post_ID
-
(int|null) (Optional) The post ID of a vehicle. Must be passed when using this method outside the loop.
Default value: null
Return Return
(array)
Source Source
File: includes/template-tags.php
function invp_get_the_photos( $sizes, $post_ID = null ) { /** * Backwards compatibility to versions before 5.4.0 where the * incoming argument was a string not an array. */ if ( ! is_array( $sizes ) ) { $sizes = array( $sizes ); } if ( empty( $post_ID ) ) { $post_ID = get_the_ID(); } $images = get_posts( array( 'meta_key' => apply_filters( 'invp_prefix_meta_key', 'photo_number' ), 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'meta_value_num', 'post_mime_type' => 'image', 'post_parent' => $post_ID, 'post_status' => 'inherit', 'post_type' => 'attachment', ) ); // Did we find any photos? if ( empty( $images ) ) { /** * No. Perhaps this vehicle has attachments, but they don't have our * meta key. Just rely on the post date for sequencing. */ $images = get_posts( array( 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'post_date', 'post_mime_type' => 'image', 'post_parent' => $post_ID, 'post_status' => 'inherit', 'post_type' => 'attachment', ) ); } $image_urls = array(); foreach ( $images as $image ) { foreach ( $sizes as $size ) { $img_element = wp_get_attachment_image( $image->ID, $size, false, array( 'class' => "attachment-$size size-$size invp-image" ) ); $image_urls[ $size ][] = $img_element; if ( 'large' === $size ) { $image_urls['urls'][] = INVP::extract_image_element_src( $img_element ); } } } /** * Backwards compatibility to versions before 5.4.0 where the * incoming argument was a string not an array. */ if ( 1 === count( $sizes ) && 'large' !== $sizes[0] ) { return $image_urls[ $sizes[0] ]; } return $image_urls; }
Expand full source code Collapse full source code View on Github