Skip to content

Commit

Permalink
Fix incorrect featured image
Browse files Browse the repository at this point in the history
  • Loading branch information
phpbits committed Jul 26, 2024
1 parent 3a45cb9 commit b3f6c15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/classes/DistributorPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,18 +796,19 @@ 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,
);

$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;
}

Expand Down

0 comments on commit b3f6c15

Please sign in to comment.