Support » Plugin: Ultimate Member - User Profile & Membership Plugin » Diplay meta key value with PHP

  • throm17

    (@throm17)


    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,

Viewing 4 replies - 1 through 4 (of 4 total)
  • SuitePlugins

    (@suiteplugins)

    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')

    throm17

    (@throm17)

    Hi @suiteplugins,

    This code don’t working, do you have any other idea ?

    Thanks !

    SuitePlugins

    (@suiteplugins)

    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;
    }
    throm17

    (@throm17)

    Where i need placed my meta key in the second code ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Diplay meta key value with PHP’ is closed to new replies.