Diplay meta key value with PHP
-
Hi,
I’ve created php scripts to display user information, but some information does not appear when I use the same code.
For example with the code and meta key : ‘percing_body’
$user_id = um_user(‘ID’);
um_fetch_user( $user_id );
$meta_value = um_user(‘percing_body’);
echo $meta_value;I am very good at displaying the value, but with a different meta key, example: ‘role_select_18’, nothing is displayed. Yet I use the same code beginning.
Do you have any idea ?
Regards,
-
Hi @throm17
Try using this custom function
function custom_get_um_user_data( $meta_key = '', $user_id = 0 ) { if ( ! $meta_key ) { return; } if ( ! $user_id ) { $user_id = um_get_requested_user(); } $return_value = ''; um_fetch_user( $user_id ); $meta_value = um_user( $meta_key ); // If the value is an array and it isn't empty. if ( ! empty( $meta_value ) && is_array( $meta_value ) ) { $return_value = implode( ', ', $meta_value ); } elseif ( ! emtpy( $meta_value ) ) { $return_value = $meta_value; } um_reset_user(); return $return_value; }You can use the function like this
echo custom_get_um_user_data('percing_body')function custom_get_um_user_data( $meta_key = '', $user_id = 0 ) { if ( ! $meta_key ) { return; } if ( ! $user_id ) { $user_id = um_get_requested_user(); } $return_value = ''; um_fetch_user( $user_id ); $meta_value = um_user( $meta_key ); // If the value is an array and it isn't empty. if ( ! empty( $meta_value ) && is_array( $meta_value ) ) { $return_value = implode( ', ', $meta_value ); } elseif ( ! empty( $meta_value ) ) { $return_value = $meta_value; } um_reset_user(); return $return_value; }There was a typo in it.
This one below is a way to debug things though
function custom_get_um_user_data( $meta_key = '', $user_id = 0 ) { if ( ! $meta_key ) { return; } if ( ! $user_id ) { $user_id = um_get_requested_user(); } echo ' User ID is '. $meta_value; $return_value = ''; um_fetch_user( $user_id ); $meta_value = um_user( $meta_key ); // If the value is an array and it isn't empty. if ( ! empty( $meta_value ) && is_array( $meta_value ) ) { $return_value = implode( ', ', $meta_value ); } elseif ( ! empty( $meta_value ) ) { $return_value = $meta_value; } echo ' Return Value is '. $meta_value; um_reset_user(); return $return_value; }-
This reply was modified 7 years, 1 month ago by
SuitePlugins.
Where i need placed my meta key in the second code ?
-
This reply was modified 7 years, 1 month ago by
The topic ‘Diplay meta key value with PHP’ is closed to new replies.