get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Batches over every request in any status. $wpdb->prepare( 'SELECT ID FROM %i WHERE post_type = %s AND ID > %d ORDER BY ID LIMIT 500', $wpdb->posts, RequestPostType::NAME, $last_id ) ); foreach ( $ids as $id ) { $last_id = (int) $id; ++$checked; $stored = metadata_exists( 'post', $last_id, RequestPostType::META_VOTES ) ? self::get( $last_id ) : null; if ( VoteRepository::count( $last_id ) !== $stored ) { self::sync( $last_id ); ++$fixed; } } } while ( $ids ); return [ 'checked' => $checked, 'fixed' => $fixed, ]; } }