diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-top-posts-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-top-posts-helper.php index 28325c3d67e9b..bb002d44cfa38 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-top-posts-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-top-posts-helper.php @@ -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. diff --git a/projects/plugins/jetpack/changelog/fix-top-posts-deleted b/projects/plugins/jetpack/changelog/fix-top-posts-deleted new file mode 100644 index 0000000000000..9a4460a2ad2ac --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-top-posts-deleted @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Top Posts & Pages Block: ensure deleted content does not display.