A dual photonic–phononic crystal slot nanobeam with a gradient cavity for liquid sensing is proposed and analyzed using the finite-element method. Based on the photonic and phononic crystals with mode bandgaps, both optical and acoustic waves can be confined within the slot and holes to enhance interactions between sound/light and analyte solution. The incorporation of a gradient cavity can further concentrate energy in the cavity and reduce energy loss by avoiding abrupt changes in lattices. The newly designed sensor is aimed at determining both the refractive index and sound velocity of the analyte solution by utilizing optical and acoustic waves. The effect of the cavity gradient on the optical sensing performance of the nanobeam is thoroughly examined. By optimizing the design of the gradient cavity, the photonic–phononic sensor has significant sensing performances on the test of glucose solutions. The currently proposed device provides both optical and acoustic detections. The analyte can be cross-examined, which consequently will reduce the sample sensing uncertainty and increase the sensing precision.