Skip to content

Commit

Permalink
Merge pull request #1254 from 10up/fix/incorrect-featured-image
Browse files Browse the repository at this point in the history
Fix incorrect featured image
  • Loading branch information
dkotter authored Aug 15, 2024
2 parents 37e11cb + ccaedc8 commit 1f82529
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 @@ -802,18 +802,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 1f82529

Please sign in to comment.