Atmega328p-mu running at incorrect clock speed

When I try to flash code to the Atmega328p-mu QFN on my custom pcb, it appears to be running at the wrong clock speed. I was able to fix this on some boards buy creating a new board in the IDE and flashing it with that parameter, with 1.6mhz instead of 16mhz. But not all boards are working correctly that way, and it seems like a bad fix.

I don't see any reason why this is happening, as there is no issue flashing my other atmega328p processors, which were in either QFP or DIP packages. Not to mention that it has an external 16mhz resonator that should be forcing it to run at that speed (and I have tried replacing the resonator and that does nothing).

I should add that these are totally blank chips from the factory.

Any ideas on how I can stop this behavior?

Did you load the fuses first? That is what determines whether the 16 MHz crystal or resonator gets used.
If not, the chip runs on 8 MHz internal RC / 8 = 1 MHz and acts like you describe.

You need a Programmer to connect to the ICSP pins to access/load the fuses.

I seem to have found a fix, by just flashing the bootloader and then flashing the code as normal. Is there a better way to do this? Such as an argument in AVRdude? I've been searching for such an argument and I can't really find one.

Is there a better way to do this?

Simply change the fuses, as already mentioned. But if you need the bootloader, flashing it accomplishes both.