re-added max_images check

props @mexon
This commit is contained in:
Matthias Pfefferle 2023-01-12 22:21:48 +01:00
parent 6992fbbe22
commit c06a7d44cf

View file

@ -88,26 +88,30 @@ class Post {
$id = $this->post->ID; $id = $this->post->ID;
$image_ids = array(); $image_ids = array();
// list post thumbnail first if this post has one // list post thumbnail first if this post has one
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) { if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
$image_ids[] = \get_post_thumbnail_id( $id ); $image_ids[] = \get_post_thumbnail_id( $id );
$max_images--; $max_images--;
} }
// then list any image attachments
$query = new \WP_Query( if ( $max_images > 0 ) {
array( // then list any image attachments
'post_parent' => $id, $query = new \WP_Query(
'post_status' => 'inherit', array(
'post_type' => 'attachment', 'post_parent' => $id,
'post_mime_type' => 'image', 'post_status' => 'inherit',
'order' => 'ASC', 'post_type' => 'attachment',
'orderby' => 'menu_order ID', 'post_mime_type' => 'image',
'posts_per_page' => $max_images, 'order' => 'ASC',
) 'orderby' => 'menu_order ID',
); 'posts_per_page' => $max_images,
foreach ( $query->get_posts() as $attachment ) { )
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) { );
$image_ids[] = $attachment->ID; foreach ( $query->get_posts() as $attachment ) {
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
$image_ids[] = $attachment->ID;
}
} }
} }