A couple of points:
You'll need to apply that technique to your query yourself, I couldn't tell quite what your query would look like with just your php/where clause partial, so I just posted a simple example.
You might need a UNION ALL if you need all rows and have duplicates, since UNION drops duplicates by default.
Next time you might wanna post your schema and the generated SQL query that is causing the problem, it's easier to work with.
No biggie on those, just FYI.