This is very niche issue, and I’m posting this mainly as a reminder to myself and hopefully to save someone else spending hours of their life stuck on a seemingly impossible to detect bug.
I needed to update a client site recently that I’ve been maintaining on a retainer for many years. The request was to create a new custom post type and then add that to the main blog feed. I’d done the exact same thing a few years ago, so I knew that all I had to use a pre_get_posts function to add the new custom post type in.
But it didn’t work. Nada. Zip. Custom Post Types I’d made years ago would work if I added them, but this new one, and any new ones I created wouldn’t register, even if the post type variables were all exactly the same. StackOverflow and ChatGPT lead me to lots of dead ends.
Disabling all the sites plugins eventually lead me to the correct answer. The site is a multi-lingual site powered by WPML, which was the only plugin I couldn’t disable (as doing so caused a fatal error). And then I found, in the depths of the WPML settings this panel:
Even though I wasn’t using the other languages in this update, due to the way WPML works, I had to set the new post type to be ‘Translatable’ for the pre_get_posts function to work. And that was it, one button click 🤦🏻♂️