The answer is “take the array from the tax_query argument in the first query, insert it into the second and change the relation to OR”.
In other words, to use a single query with the following in the arguments …
(As stated before, $terms_list_ids
was already generated; it contains the IDs of Company terms which have meta that matches the current Topic term).
Credit for the answer goes to a Reddit user.
// taxonomies
'tax_query' => array(
'relation' => 'OR',
// Posts related to a Company with this Topic...
array(
'taxonomy' => 'company',
'field' => 'id',
'terms' => $terms_list_ids,
'include_children' => true, // <<< IMPORTANT
),
// Or...
// Posts with this Topic directly...
array(
'taxonomy' => 'topic',
'field' => 'slug',
'terms' => $topic_term->slug,
'include_children' => false,
),
),