Out of nowhere, a site we were helping with started displaying 404 errors for most of its posts. (But, not all. And with no discernible pattern.) Confusingly, most of the missing posts were where they were supposed to be.
Luckily, we’ve seen this before.
The quick fix that works much of the time is to go to Settings > Permalinks, and just hit ‘save changes.’ Whether or not you’ve changed anything, this forces WordPress to flush its permalinks cache.
Flushing the general website cache is often not enough; flushing the permalinks cache is.
(In some cases, the problem returns, so keep your eye on it if you use this solution. If it comes back, the problem might be a deeper issue with the .htaccess file, or something else.)