Hi @makmerghen
Could you please share the code for the shortcode here so we can review it?
Regards,
Dear @champsupertramp
this is the code
// Display field data of Ultimate Member
// e.g. [um_field_data userid="10' field="company_name"]
add_shortcode( 'um_field_data', 'um_custom_field_shortcode' );
if ( ! function_exists( 'um_custom_field_shortcode' ) ) {
function um_custom_field_shortcode( $atts = array() ){
$defaults = array(
'field' => NULL,
'userid' => NULL,
);
$atts = wp_parse_args( $atts, $defaults );
extract( $atts );
ob_start();
$user_id = um_user($atts['userid']);
um_fetch_user( $user_id );
$meta_value = um_user($atts['field']);
print_r($meta_value);
$shortcode_content = ob_get_contents();
ob_end_clean();
return $shortcode_content;
}
}
best regards
Hi @makmerghen
Try this code snippet:
add_shortcode( 'um_field_data', 'um_custom_field_shortcode' );
if ( ! function_exists( 'um_custom_field_shortcode' ) ) {
function um_custom_field_shortcode( $atts = array() ){
$defaults = array(
'field' => NULL,
'userid' => um_profile_id(),
);
$atts = wp_parse_args( $atts, $defaults );
extract( $atts );
ob_start();
if( "user_id" == $atts['field'] ){
return $atts['userid'];
}
$user_id = um_user($atts['userid']);
um_fetch_user( $user_id );
$meta_value = um_user($atts['field']);
print_r($meta_value);
$shortcode_content = ob_get_contents();
ob_end_clean();
return $shortcode_content;
}
}
Usage: [um_field_data field=user_id]
– returns the currently logged-in user’s ID or the profile ID of the current viewing profile.
Regards,
Dear @champsupertramp thanks a lot for the code
it works only in shortcode and it appear the user id
but
in profile form the user id field still disappeared and if I enter edit profile I found the field as empty text field
so please advise
best regards
Hi @makmerghen
Did you create a text field to display the user ID? Or did you add the Content Block / Shortcode block in the Profile Form via UM Form Builder?
Regards,
Dear @champsupertramp
I added as text
even after I remove the text field and I add shorcode field
it is still disappeared in profile and even in edit profile page
so please advise
best regards
Hi @makmerghen
Are you trying to retrieve the currently logged-in user’s ID? or the profile that you’re viewing?
Please try this one:
add_shortcode( 'um_field_data', 'um_custom_field_shortcode' );
if ( ! function_exists( 'um_custom_field_shortcode' ) ) {
function um_custom_field_shortcode( $atts = array() ){
$defaults = array(
'field' => NULL,
'userid' => um_profile_id(),
);
$atts = wp_parse_args( $atts, $defaults );
extract( $atts );
ob_start();
if( "user_id" == $atts['field'] ){
return $atts['userid'];
}
um_fetch_user( $atts['userid'] );
$meta_value = um_user($atts['field']);
print_r($meta_value);
$shortcode_content = ob_get_contents();
ob_end_clean();
return $shortcode_content;
}
}
Regards,
Dear @champsupertramp
sorry dear it was mistake from my side
both codes work so please recommend which one I should use
best regards
Dear @champsupertramp
thank you very much and best regards
Thanks for letting us know.
Regards,