Serach meta in multicheckbox fields
-
Hi everyone,
On one of my website, I’ve created multiple fields on user profile but I didn’t find a functionality to check if a specific value is set in a multicheckbox.
I did make a search in the code and I’ve find this functionality:
function wpmem_user_has_meta( $meta, $value = false, $user_id = false ) { global $wpmem; $user_id = ( $user_id ) ? $user_id : get_current_user_id(); $has_meta = false; $user_value = get_user_meta( $user_id, $meta, true ); if ( $value ) { $has_meta = ( $user_value == $value ) ? true : $has_meta; } else { $has_meta = ( $value ) ? true : $has_meta; } return $has_meta; }
Is it possible to add a new functionality or update this one with this code :
function wpmem_user_has_meta( $meta, $value = false, $user_id = false ) { global $wpmem; $user_id = ( $user_id ) ? $user_id : get_current_user_id(); $has_meta = false; $user_value = get_user_meta( $user_id, $meta, true ); if ( $value ) { // New code $has_meta = strstr( $user_value, $value ) ? true : $has_meta; // Code OotB //$has_meta = ( $user_value == $value ) ? true : $has_meta; } else { $has_meta = ( $value ) ? true : $has_meta; } return $has_meta; }
With this small change, I’m able to validate if someone has a specific meta inside of an multiple checkbox.
Thanks for your fantastic plug-in & help !
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Serach meta in multicheckbox fields’ is closed to new replies.