Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function display_multiple_users_from_acf( $atts ) {
- global $post;
- // Get the array of users from the ACF field
- $users = get_field( 'co_author', $post->ID ); // Replace 'co_author' with your actual field name
- // Check if the data is valid
- if ( ! $users || ! is_array( $users ) ) {
- return '';
- }
- $output = '<div class="acf-multi-user-list">';
- foreach ( $users as $user ) {
- if ( ! is_object( $user ) ) {
- continue;
- }
- $display_name = esc_html( $user->display_name );
- $email = esc_html( $user->user_email );
- $website = esc_url( $user->user_url );
- $avatar = get_avatar( $user->ID, 64 ); // Avatar size: 64px
- $output .= '<div class="acf-user-box" style="margin-bottom:20px;">';
- $output .= "<div class='acf-user-avatar'>{$avatar}</div>";
- $output .= "<p><strong>Name:</strong> {$display_name}</p>";
- $output .= "<p><strong>Email:</strong> {$email}</p>";
- if ( $website ) {
- $output .= "<p><strong>Website:</strong> <a href='{$website}' target='_blank'>{$website}</a></p>";
- }
- $output .= '</div>';
- }
- $output .= '</div>';
- return $output;
- }
- add_shortcode( 'acf_users_display', 'display_multiple_users_from_acf' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement