Home › Forums › General Issues › Display All elements of User's Profile info
Hi ! I am sure this question has been asked before, but I can’t seem to find out this info on forums anywhere. Here is my screenshot http://joxi.ru/E4seU_3JTJAbI8hAZk8
I am trying to achieve the follwoing: Added custom field category User, to display all subscriber role users as drop-down menu, in post. When I am in post, the drop-down shows up, I select the username, and using shortcode in the body of the post to display user profile info. Only some info displays, but AIM, Yahoo fields are not displayed. How to add those as a part of User to display on my post ?
Thank You ! Any help is greatly appreciated.
Ed
Are you using WP_User_Query to display the fields in your shortcode?
Using the user ID, you should be able to display user meta data using the info here.
For example, in your shortcode, you could do this to display their AIM name.
Hope that helps,
Osu
to onesizeup, Thank you for sending the link about WP_User_Query, I just checked and will experiment and post back with my results. I appreciate your effort ! Good day to you !
Ed
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’ );
}
The topic ‘Display All elements of User's Profile info’ is closed to new replies.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.