I’m getting the $years as input from the user. It will have one year value or multiple based on that I’ve to add to $args query how to add that below is my code. Which returns only 1st element years post.
if ( !empty($years) ) {
foreach($years as $year):
$args['date_query'] = array(
'relation' => 'OR',
array( 'year' => $year),
);
endforeach;
}
$years will have the values like
$years = array(2022,2023);
Expected output should be
$args['date_query'] = array(
'relation' => 'OR',
array( 'year' => 2022),
array( 'year' => 2023),
);