Get posts from category with custom query

It looks like this is the new part of this query causing the problem, is that right?

(SELECT term_taxonomy_id
FROM wp_BOMEGAterm_relationships
WHERE object_id = p.ID) AS categories

If so the error message is clear: a sub-select in this query should only return one row. If it returns more than one row it doesn’t know how to mash all those many rows into the one row of the rest of the query.

So you need to find a way to join all the rows of this subquery together into one row, and the SQL command GROUP_CONCAT will do that

You want to make the subquery something like:

(SELECT GROUP_CONCAT(term_taxonomy_id)
FROM wp_BOMEGAterm_relationships
WHERE object_id = p.ID) AS categories

If there were more than one term_taxonomy_id’s to be returned, they’ll then be returned in a single row comma delimited, like:

10,50,100

So you’ll need to figure out what you want to do with those.