The yellow cards can trap adults. The adults lay eggs in the soil. They hatch into larvae that eat decaying organic matter (and roots if necessary.) Then they make a tiny cocoon & hatch into an adult. By killing the larvae in the soil, the cycle should be broken. Gnats don't have any connection to plants except to eat their roots if the roots are the most attractive organic matter in the soil in which they've been deposited.
Since gnats can fly, they can come in whenever a door is opened. Those who live where winter is cold should be able to treat plants once in the fall and be done with it. In a greenhouse or where it's warm enough for gnats to be active all year (and possibly fly inside on any warmish day,) periodic prophylactic treatments would be a plan to ensure there's never a serious infestation.