• Resolved gigcity

    (@gigcity)


    I have created a new user field called picture but am having trouble referencing it. I’m using the following code to generate that page:

    function rca_list_authors() {
    
    	$authors = wp_list_authors(array(
        'orderby'       => 'post_count', 
        'order'         => 'DESC', 
        'number'        => null,
        'optioncount'   => true, 
        'exclude_admin' => false, 
        'show_fullname' => true,
        'hide_empty'    => true,
        'echo'          => true,
        'style'         => 'list',
        'html'          => true
    	)
    );
    	
    $list = '';
     
    if($authors) :
    
    		$list .= '<div class="author-list">';
    
    foreach($authors as $author) :
     
    	$list .= '<div class="author">';
     
    		$archive_url = get_author_posts_url($author->ID);
    		$archive_photo = get_avatar($author->ID, 120);
     
    		$list .= '<p>'  . $archive_photo . '</p>';
    
    		$list .= get_wp_user_avatar($author->ID, '120');
    		$list .= '<a href="'. $archive_url . '">' . $author->display_name . '</a>';
    		$list .= '<p class="author-bio>' . get_user_meta($author->ID, 'description', true) . '</p>';
    		$list .= '<p class="author-archive"><a href="'. $archive_url . '" title="' . __('View all posts by ', 'pippin') . $author->display_name . '">' . __('View author\'s posts', 'pippin') . '</a></p>';
    		$list .= '<p>'  . $author->optioncount . '</p>';	
    	$list .= '</div>';
     
    endforeach;
    	$list .= '</div>';		
     
    endif;
     
    return $list;
    
    }
    
    add_shortcode('rca_authors', 'rca_list_authors');

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    I don’t see in your code where you’re referencing picture, but basically, since images are stored in the media library, you’d use the WP methods once you had the ID of the field. Since you’ve added it as user meta, you’d access it the standard way through user_meta, so:

    Using: https://developer.ww.wp.xz.cn/reference/functions/wp_get_attachment_image_src/

    
    $image_src = wp_get_attachment_image_src( get_user_meta($author->ID, 'picture', true), 'thumbnail', false );
    
Viewing 1 replies (of 1 total)

The topic ‘Help pulling a User Custom Field’ is closed to new replies.