Title: user meta data with shortcode
Last modified: December 2, 2019

---

# user meta data with shortcode

 *  Resolved [kayapati](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/)
 * 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:](https://trello-attachments.s3.amazonaws.com/550beaf3fcaec11add7cf54b/5dd67137b9a6f16043e7988d/711be19c12ec3f74947bd2fada3f52e6/Edit_Form_%E2%80%B9_um_demo_%E2%80%94_WordPress.jpg)

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

1 [2](https://wordpress.org/support/topic/user-meta-data-with-shortcode/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/user-meta-data-with-shortcode/page/2/?output_format=md)

 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12196107)
 * Hi [@kayapati](https://wordpress.org/support/users/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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12196376)
 * [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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12196433)
 * Hi [@kayapati](https://wordpress.org/support/users/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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12202817)
 * 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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12204974)
 * Hi [@kayapati](https://wordpress.org/support/users/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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12207326)
 * 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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12212110)
 * Hi [@kayapati](https://wordpress.org/support/users/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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12212396)
 * Champ Still not working.
 * Is it working from your side?
 * Its getting empty.
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12214333)
 * Hi [@kayapati](https://wordpress.org/support/users/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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12214883)
 * No they are filled. and also those are displaying fine above this shortcode.
 * For clarifying where I am using the shortcode
 * [check this screenshot.](https://trello-attachments.s3.amazonaws.com/5dd67137b9a6f16043e7988d/600x474/51599686c81c8ba8a0ccc95e9c1cbfef/meta.jpg)
 *  Thread Starter [kayapati](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12214894)
 * [https://kayapati.com/demos/alexia/user/tesdt/](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](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12214937)
 * Hi [@kayapati](https://wordpress.org/support/users/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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12216093)
 * 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](https://trello-attachments.s3.amazonaws.com/5dd67137b9a6f16043e7988d/600x293/90a111c7a8ebb1b7aa489db2df737933/podscompr.jpg)
 * 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](https://wordpress.org/support/users/kayapati/)
 * (@kayapati)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12216425)
 * Sorry, it seems working, but only the top one country is displaying and others
   are not displaying, any thing missing?
 *  Plugin Contributor [Champ Camba](https://wordpress.org/support/users/champsupertramp/)
 * (@champsupertramp)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/#post-12216904)
 * Hi [@kayapati](https://wordpress.org/support/users/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](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)

1 [2](https://wordpress.org/support/topic/user-meta-data-with-shortcode/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/user-meta-data-with-shortcode/page/2/?output_format=md)

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

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

## Tags

 * [user meta fields](https://wordpress.org/support/topic-tag/user-meta-fields/)

 * 30 replies
 * 2 participants
 * Last reply from: [kayapati](https://wordpress.org/support/users/kayapati/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/user-meta-data-with-shortcode/page/2/#post-12232152)
 * Status: resolved