The title of this post is admittedly vague but I really don’t know what else to say: this is the weirdest WordPress bug I’ve ever encountered.

I ran into an issue today where page meta wouldn’t save, specifically neither my ACF meta nor my Yoast SEO meta. I’d fill out the field, hit update, and the field would be empty, with no reference to it ever existing in the database.

Debugging

I went through the standard debug process and deactivated all of my plugins except Yoast and tried again. Same thing. Deactivated Yoast and activated ACF… same thing.

I started considering that it was my theme. The theme is hand-rolled and uses a well-tested internal framework developed at work, so I was confident that the theme wasn’t the issue. Nonetheless, I switched to a default WordPress theme and tried again.

Same result. What the hell?

I created a new dummy page with dummy Yoast info, saved, and was shocked to see that it had saved correctly. To make sure I wasn’t crazy, I did it again, and experienced the same result: success.

From there, I started comparing the meta between the two posts. The only difference was that the original post had a meta key defining a page template. (I need to point out that this is a new template for an existing WordPress site, so the existing database was duped.)

The page template was for the previous theme. It seemed like a longshot, but I deleted the meta, edited the page, and… violà: my changes saved as expected.

The Fix

To fix/workaround the issue, I deleted all meta entries where the meta_key was _wp_page_template. There were about 50 entries.

Again… What the hell?

I started researching this issue and came across a couple WordPress tickets describing the same issue.

I learned that this bug was originally reported at least three years ago, the first patch was written 17 months ago, and a final patch was accepted 7 weeks ago in the same ticket.

The fix is set to land in 4.2, thankfully!

Long story short, if you’re building a new theme for an existing WordPress site and using a version < 4.2, it’s a good idea to delete the old page template meta when you get to the point that you won’t need it again.