• Resolved kayapati

    (@kayapati)


    I would like to display the user meta data in my profile page which is custom template.

    I added this code in theme function.php

    
    /**
     * Returns a user meta value
     * Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
     * meta_key is the field name that you've set in the UM form builder
     * You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
     */
    function um_user_shortcode( $atts ) {
    	$atts = extract( shortcode_atts( array(
    		'user_id' => get_current_user_id(),
    		'meta_key' => '',
    	), $atts ) );
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = get_current_user_id(); 
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
     
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    I added this shortcode in my profile page:

    [um_user user_id=” ” meta_key=”country”]
    [um_user user_id=” ” meta_key=”Gender”]
    [um_user user_id=” ” meta_key=”email”]

    this is the screenshot:

Viewing 15 replies - 1 through 15 (of 30 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    You don’t need to put the attribute user_id when it is empty. IF you remove the user_id attribute, it will use the logged-in user’s ID.

    Just use the following syntax:

    [um_user meta_key=”country”]
    [um_user meta_key=”Gender”]
    [um_user meta_key=”email”]

    Regards,

    Thread Starter kayapati

    (@kayapati)

    [um_user meta_key=”country”]
    [um_user meta_key=”gender”]

    I added above but no luck.

    I am trying to display meta data of That particular user profile info, not logged in users details.

    Just how the info display when we code this function in php file.

    do_action(“um_profile_content_main”, $args);

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    I got it.

    Please try this new version of UM Shortcode below:

    
    /**
     * Returns a user meta value
     * Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
     * meta_key is the field name that you've set in the UM form builder
     * You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
     */
    function um_user_shortcode( $atts ) {
    	$atts = extract( shortcode_atts( array(
    		'user_id' => get_current_user_id(),
    		'meta_key' => '',
    	), $atts ) );
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = um_profile_id(); 
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
     
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    It should display the current profile’s meta values with the same syntax below:

    [um_user meta_key=”country”]
    [um_user meta_key=”gender”]

    Regards,

    Thread Starter kayapati

    (@kayapati)

    Champ

    Sorry the code is not workig.

    I added this code in theme function.php

    
    /**
     * Returns a user meta value
     * Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
     * meta_key is the field name that you've set in the UM form builder
     * You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
     */
    function um_user_shortcode( $atts ) {
    	$atts = extract( shortcode_atts( array(
    		'user_id' => get_current_user_id(),
    		'meta_key' => '',
    	), $atts ) );
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = um_profile_id(); 
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
     
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    and add the following shortcode in profile form.

    [um_user meta_key=”country”]
    [um_user meta_key=”gender”]
    [um_user meta_key=”talent_skills”]
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    Could you please remove the get_current_user_id() from the following lines:

    $atts = extract( shortcode_atts( array(
    		'user_id' => get_current_user_id(),
    		'meta_key' => '',
    	), $atts ) );
    

    Change it to:

    $atts = extract( shortcode_atts( array(
    		'user_id' => 0,
    		'meta_key' => '',
    	), $atts ) );
    

    Let me know if this works.

    Regards,

    Thread Starter kayapati

    (@kayapati)

    Added still not working.

    This is code in theme function.php

    
    function um_user_shortcode( $atts ) {
    
    	$atts = extract( shortcode_atts( array(
    		'user_id' => 0,
    		'meta_key' => '',
    	), $atts ) );
    
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = get_current_user_id(); 
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
    
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
    
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
      
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
    
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    and the shortcode is this:

    [um_user meta_key=”country”]
    [um_user meta_key=”gender”]
    [um_user meta_key=”user_email_18_22”]

    The meta fields are not displaying.

    Note: I am adding the shortcode in User Profile Form at the bottom of the form.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    You need to keep the if( empty( $user_id ) ) $user_id = um_profile_id();

    Please see the code snippet below:

    function um_user_shortcode( $atts ) {
    
    	$atts = extract( shortcode_atts( array(
    		'user_id' => 0,
    		'meta_key' => '',
    	), $atts ) );
    
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = um_profile_id();
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
    
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
    
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
      
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
    
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    Regards,

    Thread Starter kayapati

    (@kayapati)

    Champ Still not working.

    Is it working from your side?

    Its getting empty.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    Yes, it is working on our end.

    Could you please try checking your current profiles fields? Maybe they are empty.

    Regards,

    Thread Starter kayapati

    (@kayapati)

    No they are filled. and also those are displaying fine above this shortcode.

    For clarifying where I am using the shortcode

    check this screenshot.

    Thread Starter kayapati

    (@kayapati)

    https://kayapati.com/demos/alexia/user/tesdt/

    In above url I used A Print Screen (just click the compcard button to know) of hidden images and fields which are from shortcode.

    RIght now I am duplicating the meta fields as the shortcode is not working.

    If shortcode works, I just add shortcode and the user do not need to reenter the fields in compcard screen .

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    Have you made any customization aside from the shortcode? Could you please try disabling them leaving the code for the shortcode?

    It works on our test site.

    Regards,

    Thread Starter kayapati

    (@kayapati)

    Nothing changed, just used what ever you provided.

    Are you using the shortcode in profile form?

    Check this image to get an idea how I am using

    This is added in function.php

    
    function um_user_shortcode( $atts ) {
    
    	$atts = extract( shortcode_atts( array(
    		'user_id' => 0,
    		'meta_key' => '',
    	), $atts ) );
    
    	
    	if ( empty( $meta_key ) ) return;
    	
    	if( empty( $user_id ) ) $user_id = um_profile_id();
        
        $meta_value = get_user_meta( $user_id, $meta_key, true );
    
        if( is_serialized( $meta_value ) ){
           $meta_value = unserialize( $meta_value );
        } 
    
        if( is_array( $meta_value ) ){
             $meta_value = implode(",",$meta_value );
        }  
      
        return apply_filters("um_user_shortcode_filter__{$meta_key}", $meta_value );
    
    }
    add_shortcode( 'um_user', 'um_user_shortcode' );

    This is the shortcode used in my profile form:

    [um_user meta_key='country']
    [um_user meta_key=”gender”]
    [um_user meta_key=”hair_color”]
    Thread Starter kayapati

    (@kayapati)

    Sorry, it seems working, but only the top one country is displaying and others are not displaying, any thing missing?

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @kayapati

    I’ve added the shortcode to the Profile Form and outside the form which is directly added to the User Page:
    https://drive.google.com/file/d/1Su5Rgl0gowswrVoZE5tmb7GCrPDcuxsf/view?usp=sharing

    Both ways work on our end.

    Regards,

Viewing 15 replies - 1 through 15 (of 30 total)

The topic ‘user meta data with shortcode’ is closed to new replies.