Keep trying.
With people playing Z-A actively, it makes sense there's not as many people playing the older games. However, that does not mean you can't get the codes to work. Keep trying; you just have to be lucky and catch someone online. Try at different times.
Some alternatives:
- You can try asking others on our chatroom.
- Try trading forums, like r/pokemontrades on Reddit.
- Trade on the Pokemon Home on the Mobile App.
- Ask a classmate or friend if they will trade with you.
- Join local community groups surrounding Pokemon that are in your local area, and ask them to trade.
- Buy the other game and transfer them to yourself on Pokemon Home.
Best of luck