Home › Forums › ACF PRO › Print user fields with values corresponding to that user › Reply To: Print user fields with values corresponding to that user
Yes, inside the standard post loop. Currently, I am using it inside of a shortcode, although I have tried it inside of a template page too and can’t get that to work either.
Here’s what my shortcode looks like:
function print_members( $atts ) {
$args = array(
'role' => 'pmpro_role_2',
'orderby' => 'last_name',
'order' => 'ASC'
);
$users = get_users( $args );
$other_user_id = get_the_author_meta('ID');
echo '<div>';
foreach ( $users as $user ) {
echo '<div><h3>' . esc_html( $user->first_name ) . ' ' . esc_html( $user->last_name ) . '</h3>';
echo '<p>Email: <a href="mailto:' . esc_html( $user->user_email ) . '">' . esc_html( $user->user_email ) . '</a></p>';
echo '<p>Mailing Address: ';
echo the_field('address_line_1', 'user_'. $other_user_id );
echo '<br>';
echo the_field('address_line_2', 'user_' . $other_user_id );
echo '<br>';
echo the_field('city', 'user_'. $other_user_id );
echo ', ';
echo the_field('state', 'user_'. $other_user_id );
echo'<p></div>';
}
echo '</div>';
}
add_shortcode('member-list', 'print_members');
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.