Thanks a lot @jarvis for your time and patience, I really appreciate it!
Your code is working perfectly, and no more critical error for me! I’m very happy to continue building my website now 🙂
My menu disappeared though, but I found a solution here by using a $query->is_main_query()
if anyone has the same problem.