Skip to content

Commit

Permalink
Top Posts & Pages Block: Remove Deleted Content (#37251)
Browse files Browse the repository at this point in the history
* Changelog

* Top Posts & Pages Block: Filter Deleted Content
  • Loading branch information
Aurorum committed Aug 22, 2024
1 parent 5710d25 commit 58080fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public static function get_top_posts( $period, $items_count = null, $types = nul
$data = array( 'summary' => array( 'postviews' => array() ) );
}

// Remove posts that have subsequently been deleted.
$data['summary']['postviews'] = array_filter(
$data['summary']['postviews'],
function ( $item ) {
return get_post_status( $item['id'] ) === 'publish';
}
);

$posts_retrieved = is_countable( $data['summary']['postviews'] ) ? count( $data['summary']['postviews'] ) : 0;

// Fallback to random posts if user does not have enough top content.
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-top-posts-deleted
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Top Posts & Pages Block: ensure deleted content does not display.

0 comments on commit 58080fd

Please sign in to comment.