diff --git a/includes/classes/DistributorPost.php b/includes/classes/DistributorPost.php index fef6d0c18..26dd2a7f2 100644 --- a/includes/classes/DistributorPost.php +++ b/includes/classes/DistributorPost.php @@ -633,7 +633,7 @@ protected function get_media() { $media_array = array(); foreach ( $raw_media as $media_post ) { - $media_item = Utils\format_media_post( $media_post ); + $media_item = Utils\format_media_post( $media_post, $post_id ); if ( $media_item['featured'] ) { $found_featured = true; diff --git a/includes/utils.php b/includes/utils.php index 1e53a57f9..946e1b99e 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -796,10 +796,11 @@ function set_media( $post_id, $media, $args = [] ) { * This is a helper function for transporting/formatting data about a media post * * @param \WP_Post $media_post Media post. + * @param int $post_id Post ID. * @since 1.0 * @return array */ -function format_media_post( $media_post ) { +function format_media_post( $media_post, $post_id = 0 ) { $media_item = array( 'id' => $media_post->ID, 'title' => $media_post->post_title, @@ -807,7 +808,7 @@ function format_media_post( $media_post ) { $media_item['featured'] = false; - if ( (int) get_post_thumbnail_id( $media_post->post_parent ) === $media_post->ID ) { + if ( $post_id && (int) get_post_thumbnail_id( $post_id ) === $media_post->ID ) { $media_item['featured'] = true; }