I have an array of post_ids
$ids = array(
[0] => 32
[1] => 33
[2] => 21
[3] => 11
[4] => 13
[5] => 17
[6] => 41
[7] => 88
[8] => 92
[9] => 94
[10] => 96
[11] => 106
[12] => 117
[13] => 187
[14] => 220
);
I want to get a column in database table where the post_id matches the ids in the above array. the table is structured like this
post_id | meta_key | meta_value
Currently, I’m using foreach ($ids as $id) to query a var one by one. This is inefficient with large data sets . Is there a way to query the meta_value column by the $ids array?
This is not the most efficient way but it works
now your query
at least now it is reduced to one query
Update:
To secure from SQL injection when you populate your array make sure the your database input is safe: