
Hey folks,
This is not really an issue or a bug or even a question. It’s just an observation from a little incident I had this morning with a client site that I thought I would share with others.
While it’s perfectly fine using ACF functions withing your functions.php page, I learned the hard way that if you add a function like get_field() inside a script hooked up to pre_get_posts, it will wipe out your entire functions.php file and save it blank.
That was fun to discover. I suppose it makes sense in hindsight, depending on when those functions get called. But I did not expect a blank functions.php file after making that mistake! I tested further later by editing the file directly instead, and it returned a 500 error on the page (but at least it didn’t wipe the file out).
Once I restored the file, I moved my ACF call outside of the function, made the result global and pulled it into the pre_get_posts function. But that was a scary moment!
Any further observations or explanations are welcome, but not necessary. Just passing this along 🙂