This is how to use MySQL IN Operator in prepare statement in WordPress. Let me straight away give you the code.
global $wpdb; $agenda_id_arr = $wpdb->get_results( $wpdb->prepare( 'SELECT agenda_id FROM ' . $agenda_bookmark_tbl . ' WHERE user_id = %d', $user_id ), "ARRAY_A" ); foreach( $agenda_id_arr as $agenda_id ){ $agenda_ids[] = $agenda_id['agenda_id']; } $in = implode(',', array_fill(0, count($agenda_ids), '%d')); $agenda_list_arr = $wpdb->get_results( $wpdb->prepare( ' SELECT * FROM ' . $agenda_tbl . ' WHERE id in ('. $in .') ', $agenda_ids), "ARRAY_A" );
Page Contents
Listed a few important links to refer.
Was that a useful Article? Let me know your comments & feedback. Do I need any edits in the code?