One solution may be to get all position ids, where project id matches and compare them with the ‘OR’ comparer.
$position_ids = get_positions_in_project($project_id);
foreach ($position_ids as $id) {
$meta_query[] = array(
'key' => 'feedback_position_relation',
'value' => $id,
'compare' => '=',
);
}
$meta_query['relation'] = 'OR';
$query->set('meta_query', $meta_query)
But the problem with this is, that meta query does not accept complex parameters. I want a feedback where the position id is 1 and project id is 2. The relation will always be ‘OR’.
In a simple problem this solution should give the answer. For my sake this solution does not work, since i want to give the user the ability to filter other parameters too.
I have searched for ‘in array’ meta_query, but this seems to be not supported.
UPDATE
With wordpress 5.8.1 (I have no idea if earlier versions work), the IN Array comparison works.
if ($_GET['project'] != 'all') {
$project_id = $_GET['project'];
$positions = get_position_ids_by_project($project_id);
$meta_query[] = array(
'key' => 'summary_summary_position',
'value' => $positions,
'compare' => 'IN',
);
}
$query->set('meta_query', $meta_query)