I have the following PHP function to fetch some user_ids which I would then like to add as recipients to a message as per below.
function true_my_bp_get_users_by_xprofile( $field_id_to_check, $num_to_find ) {
global $wpdb;
$table_name = $wpdb->prefix . "bp_xprofile_data";
$user_ids = $wpdb->get_results(
$wpdb->prepare(
"SELECT user_id FROM $table_name
WHERE field_id = %d AND value LIKE '%%\"%d\"%%'",
$field_id_to_check,
$num_to_find
)
);
print_r($user_ids);
}
I am using true_my_bp_get_users_by_xprofile( 5, 18 );
which prints Array ( [0] => stdClass Object ( [user_id] => 1 ) [1] => stdClass Object ( [user_id] => 2 ) )
Then I have a HTML form with this code:
$body_input=isset($_POST['body_input'])?$_POST['body_input']:'';
$subject_input=isset($_POST['subject_input'])?$_POST['subject_input']:'';
send_msg( $user_ids,$body_input, $subject_input);
With send_msg
being
function send_msg($user_id, $title, $message){
$args = array( 'recipients' => $user_id, 'sender_id' => bp_loggedin_user_id(), 'subject' => $title, 'content' => $message );
messages_new_message( $args );
}
What I want to do:
Take the array from $user_ids
and put it here: 'recipients' => $user_id
I have tried replacing $user_id with $user_ids in the function but it doesn't work.