I have a big categories tree, around 2000 subcategories, and I have a lot of posts with a custom field
city (different values).
I have created filter posts by "city" field. But I have a problem with categories list. I just need to show all categories that have 1+ posts with needed value in the
If I get all categories in an array and check the number of posts by the custom field in each category in a loop - that will create thousands of DB queries. I need a more accurate solution to do this.