Hello Ravi,
Thank you very much for your feedback.
Your code works perfect and gives the results you mentioned. However what i need is:// If all three options are selected.
TEXT WILL BE SEND// If option Music and option Food are selected.
TEXT WILL BE SEND// If option Music and option Movie are selected.
TEXT WILL BE SEND// If option Movie and option Food are selected.
TEXT WILL BE SEND// If only option Movie is selected.
TEXT WILL BE SEND// If only option Food is selected.
TEXT WILL BE SEND// If only option Music is selected.
TEXT WILL BE SENDThe text is irrelevant to the conditions programmatically and dont need to fetch the array
$datainside the$message. Just need the conditions for every option of the user.Regards Lefteris
Hello Lefteris,
Thank you for the detailed acknowledgement. Please use the following code with as many possible conditions:
$data = (array) xprofile_get_field_data( 12, 23 ); $is_selected_music = in_array( 'Music', $data ); $is_selected_food = in_array( 'Food', $data ); $is_selected_movies = in_array( 'Movies', $data ); $message = ''; // Example for all selected. if ( $is_selected_food && $is_selected_movies && $is_selected_music ) { $message = __( 'All are selected' ); } echo esc_html( $message );Please let me know if it helps or not.
Regards
Ravi- This reply was modified 3 years, 7 months ago by
Ravi.
- This reply was modified 3 years, 7 months ago by
Hello Ravi,
Thank you very much for your feedback.Your code is giving the appropriate results. However the problem with this logic is that when user is checking
$is_selected_food && $is_selected_moviesthe output isFOOD, MOVIE, FOOD & MOVIES. Actually it outputs all the 3 true cases :$is_selected_moviesMOVIE
$is_selected_foodFOOD
$is_selected_food && $is_selected_moviesFOOD & MOVIESI have used only if statements inside my wp_mail.
if ( empty( $data ) ) { // some html}
if ( $is_selected_movies ) {// some other html}`
if ( $is_selected_food ) { // some other html}and so on…If i set
elseif, then i dont get correct results.If
$is_selected_food && $is_selected_moviesshould be only this true.Regards Lefteris
Hello Lefteris,
Try this
$data = (array) xprofile_get_field_data( 12, 23 ); $is_selected_music = in_array( 'Music', $data ); $is_selected_food = in_array( 'Food', $data ); $is_selected_movies = in_array( 'Movies', $data ); $message = ''; // Example for all selected. if ( $is_selected_food && $is_selected_movies && $is_selected_music ) { $message = __( 'All are selected' ); } elseif ( $is_selected_music && $is_selected_movies ) { $message = __( 'Music and Movies are selected' ); } elseif ( $is_selected_food && $is_selected_movies ) { $message = __( 'Food and Movies are selected' ); } elseif ( $is_selected_food && $is_selected_music ) { $message = __( 'Food and Music are selected' ); } elseif ( $is_selected_movies ) { $message = __( 'Movie is selected' ); } elseif ( $is_selected_music ) { $message = __( 'Music is selected' ); } elseif ( $is_selected_food ) { $message = __( 'Food is selected' ); } else { $message = __( 'No option is selected' ); } echo esc_html( $message );Regards
Ravi
The topic ‘ [Resolved] Fetch and condition for checkboxes data values’ is closed to new replies.