Controlling the interaction between photons is one of the important technologies applied to quantum information processing at the few-photon level. We investigate the two-photon interaction via a Ξ-type atom, where one atomic transition is coupled to a one-dimensional waveguide, and the other transition is coupled to a cavity field. Whether the cavity is initially in the vacuum state or not, determines the effective configuration of the quantum emitter. When the cavity is in the vacuum state, only one bound state appears. We further found that the joint probability of transmitted photons oscillates with their spatial separation due to the coexistence of two bound states, if the cavity is in fock state |n〉 (n ≠ 0). With the incoming wave function consists entirely of plane waves, we present the exact out-state function that exhibit the bunching and antibunching behaviors. And, we discuss in detail with the behaviors of varying both the photon pair energy(E) and the energy difference between the two photons (Δ). Moreover, the spatial attraction and repulsion between the two transmitted photons can be controlled by the parameters of the cavity.