yousuf patel yousuf patel - 1 month ago 4
PHP Question

Wordpress query for IN operator with multiple AND in where clause

I need a WordPress query for IN operator with multiple AND in where clause.

$query="SELECT event FROM $wpdb->prifix.wp_rsvpmaker rsvp WHERE user_id IN ($format) AND event != %d
UNION ALL
SELECT eventid
FROM $wpdb->prifix.wp_payment_event WHERE pay_user_id IN($format) AND eventid !=%d";

$value[]=$usersRegisteFrOtherEvents;
$value[]=$eventid;
$value[]=$usersRegisteFrOtherEvents;
$value[]=$eventid;

$eventIDs = $wpdb->get_results($wpdb->prepare($query,$value),ARRAY_A);

Answer

Try with this code, make sure that all placeholders are correct in your array while passing to the prepare statement:

 $how_many = count($usersRegisteFrOtherEvents);
 $placeholders = array_fill(0, $how_many, '%d');
 $format = implode(', ', $placeholders);