I need your help. I’m working on a small plugin for some email verifications in wordpress and now I’m struggeling.

I want to get an array of ID’s and I get them by following code:

function myFuntion () {
        global $wpdb;
        $supporterIDArray = $wpdb->get_results("SELECT id FROM myTable WHERE value = 'true' AND field_id = 1");

Now I get an array of an unknown number of ID’s like [7, 9, 34, 53, …]

After that I want to count how many other rows have this ID. But I don’t know how to do that, the could shold be like this…

global $wpdb;
$countSupporters = $wpdb->get_results("SELECT COUNT(*) AS allSupporter FROM myTable WHERE value = 'true' AND field_id = '2' AND `id` = **THESE IDS FORM THE ARRAY**");
echo $countSupporters -> allSupporter; /*Number of all ROWs which have an ID wich was in the array

I hope I explained it good enough and would be so grateful if you could help me. Thanks!

Read more here: WordPress SQL request with data from array in WHERE clause


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: