Don’t implode $artistNames
. The value
meta_query
argument will take an array if you use any of several compare
arguments. You need IN
, I believe.
value (string|array) – Custom field value. It can be an array only
when compare is ‘IN’, ‘NOT IN’, ‘BETWEEN’, or ‘NOT BETWEEN’….http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Assuming that $artistNames
is an array of id
s you can use it directly.
$args = array(
'post_type' => array ( 'songs', 'videos' ),
'meta_query' => array(
array(
'key' => 'artist_name',
'value' => $artistNames,
'compare' => 'IN'
)
)
);
And in fact, it looks like you can skip that first foreach
that generates $artistNames
and just use $my_id
.
$args = array(
'post_type' => array ( 'songs', 'videos' ),
'meta_query' => array(
array(
'key' => 'artist_name',
'value' => $my_id,
'compare' => 'IN'
)
)
);