"the foxholes" being those of WWII, which was going on when this phrase was popularized. Attributed sometimes to Douglas McArthur, but c.f. "There are no athiests in foxholes", which was said by William T. Cummings.

Interpretation of the phrase varies depending on the speaker, however it is generally used to point out people's inconstancy in their beliefs.