I’m trying to create an array that looks like below.
$arr = array(
'post_type' => 'smart_contract',
'post_status' => 'publish',
'author' => $user_id,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'contract_type',
'value' => 'erc721-nft',
'compare' => '=',
),
array(
'key' => 'contract_type',
'value' => 'erc721-sbt',
'compare' => '=',
),
),
);
But if you look at meta_query
, I’m expecting more than two nested arrays (value => erc721-nft and value => erc721-sbt
). So, I’m using a for-loop to add these in as below. I’m using array_merge
but it overwrites the values instead of adding in more nested arrays.
foreach ( $contract_types as $contract_type ) {
$or_array2 = array(
'key' => 'contract_type',
'value' => $contract_type,
'compare' => '=',
);
$or_array = array_merge( $or_array, $or_array2 );
}
How can I append more nested arrays without any overwriting?
2
Answers
so you just want to add the
contracts
to themeta_query
underrelation => OR
right ? You could do something like this:^ above will result in:
I’m not quite sure what you want to achieve, you should improve your question, meanwhile you could try with: