Home › Forums › General Issues › Display All elements of User's Profile info › Reply To: Display All elements of User's Profile info
This is what worked for me, by inserting the code into Functions.php
in admin dashboard, inside post, I type in short code like this:
[get_all_user_fields post_field=”user_aim” ], and i get all profile fields shown on front end. Hope this will help someone else.
}
if(! function_exists(‘get_all_user_fields_func’)) {
function get_all_user_fields_func( $atts ) {
extract( shortcode_atts( array(
‘post_field’ => ‘user_aim’,
), $atts ) );
$fieldsList = array(
“first_name” => “First Name”,
“last_name” => “Last Name”,
“text_aim” => “AIM”
);
$postId = get_the_ID();
$customFields = get_post_custom($postId);
if (isset($customFields[$post_field])) {
$userID = $customFields[$post_field][0];
}
else {
$userID = 0;
}
// The Query
$user_query = new WP_User_Query( array( ‘include’ => array( $userID ) ) );
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
foreach ( $fieldsList as $fieldName => $fieldLabel) {
$user_field = get_user_meta($userID, $fieldName);
if (isset($user_field[0])) {
$fieldValue = $user_field[0];
$out .= “<b>$fieldLabel<b>: «$fieldValue» <br/>”;
}else {
$out .= “<b>$fieldLabel<b> is not filled <br/>”;
}
}
}
} else {
$out = ‘No users found at all.’;
}
return $out;
}
add_shortcode( ‘get_all_user_fields’, ‘get_all_user_fields_func’ );
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.