'breznflow_workflow', 'post_status' => 'publish', 'posts_per_page' => $limit, 'post__not_in' => array( $post_id ), // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query array( 'key' => '_breznflow_node_summary', 'compare' => 'EXISTS', ), ), ) ); // Filter by shared node types. $scored = array(); foreach ( $related as $post ) { $other_summary = get_post_meta( $post->ID, '_breznflow_node_summary', true ); if ( ! $other_summary ) { continue; } $other_types = array_keys( (array) json_decode( $other_summary, true ) ); $shared = count( array_intersect( $node_types, $other_types ) ); if ( $shared > 0 ) { $scored[] = array( 'post' => $post, 'shared' => $shared, ); } } usort( $scored, static function ( $a, $b ) { return $b['shared'] - $a['shared']; } ); $result = array_column( array_slice( $scored, 0, $limit ), 'post' ); set_transient( $cache_key, $result, HOUR_IN_SECONDS ); return $result; } }