Gas-liquid two-phase flow pipelines are commonly found in building thermal systems. However, the attachment on the inner wall of the pipeline brings great safety hazards to the system. At present, ultrasonic guided wave technology has been widely used for the structural inspection of pipelines. The boundary conditions significantly affect the propagation characteristics of ultrasonic guided waves and the detection accuracy. Therefore, this paper investigates the influence of the flow pattern on the propagation characteristics of guided waves using semi-analytical finite element method and proposes an excitation frequency selection method independent of the flow pattern to improve the accuracy of the detection of attachments in gas-liquid two-phase flow pipelines. The relationship between the attachment size and the reflection echo characteristics is analyzed. Numerical simulation and experimental results show that the flow pattern leads to the modal coupling phenomenon of the L(0,1) guided wave, and the modes vary with the spatial distribution of the gas plug. The attachment echo contains not only the attachment information but also the position of the gas plug in the fluid. Finally, the maximum error of the attachment position accuracy in two-phase flow pipes with different flow patterns is no more than 3 %. An innovative dispersive surface result reflecting the changes in the propagation characteristics of UGWs along a pipe with changing cross-section (plug flow) is established.