Viewing 2 replies - 1 through 2 (of 2 total)
  • Try using these arguments in your WP_Query

    $args = array(
    'order' => 'ASC',
    'orderby' => 'meta_value',
    'meta_key' => 'cap-last_name'
    );
    Thread Starter twalterswx

    (@twalterswx)

    Still no luck, this is currently what I got in my coauthors_wp_list_authors function:

    function coauthors_wp_list_authors( $args = array() ) {
    	global $coauthors_plus;
    	$defaults = array(
    		'optioncount'      => false,
    		'show_fullname'    => false,
    		'hide_empty'       => true,
    		'feed'             => '',
    		'feed_image'       => '',
    		'feed_type'        => '',
    		'echo'             => true,
    		'style'            => 'list',
    		'html'             => true,
    		'number'           => 300, // A sane limit to start to avoid breaking all the things
    	);
    
    	$args = wp_parse_args( $args, $defaults );
    	$return = '';
    
    	$term_args = array(
    			'order' => 'ASC',
    			'orderby' => 'meta_value',
    			'meta_key' => 'cap-last_name',
    			'hide_empty'   => 0,
    			'number'       => (int)$args['number'],
    		);
    	$author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args );
    	$authors = array();
    	foreach( $author_terms as $author_term ) {
    		// Something's wrong in the state of Denmark
    		if ( false === ( $coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $author_term->name ) ) )
    			continue;
    
    		$authors[$author_term->name] = $coauthor;
    
    		$authors[$author_term->name]->post_count = $author_term->count;
    	}
    
    	foreach ( (array) $authors as $author ) {
    
    		$link = '';
    
    		if ( $args['show_fullname'] && ( $author->first_name && $author->last_name ) )
    			$name = "$author->first_name $author->last_name";
    
    		else
    			$name = $author->display_name;
    
    		if ( ! $args['html'] ) {
    			if ( $author->post_count == 0 ) {
    				if ( ! $args['hide_empty'] )
    					$return .= $name . ', ';
    			} else
    				$return .= $name . ', ';
    
    			// No need to go further to process HTML.
    			continue;
    		}
    
    		if ( ! ( $author->post_count == 0 && $args['hide_empty'] ) && 'list' == $args['style'] )
    			$return .= '<section class="author-info">';
    		if ( $author->post_count == 0 ) {
    			if ( ! $args['hide_empty'] )
    				$link = $name;
    		} else {
    			$link = get_avatar($author->user_email, 100) .'<div class="description"><a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf( __("Posts by %s", 'co-authors-plus' ), $name ) ) . '">' . esc_html( $name ) . '</a></br><p class="bio">' . $author->description. '</p><span class="posts"><a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" class="button smaller" title="Browse Author Articles"><strong>'. $author->post_count .'</strong> Articles</a></span>';
    
    			if ( (! empty( $args['feed_image'] ) ) || ( ! empty( $args['feed'] ) ) ) {
    				$link .= ' ';
    				if ( empty( $args['feed_image'] ) )
    					$link .= '(';
    				$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
    
    				if ( !empty( $args['feed'] ) ) {
    					$title = ' title="' . esc_attr( $args['feed'] ) . '"';
    					$alt = ' alt="' . esc_attr( $args['feed'] ) . '"';
    					$name = $feed;
    					$link .= $title;
    				}
    
    				$link .= '>';
    
    				if ( ! empty( $args['feed_image'] ) )
    					$link .= "<img src=\"" . esc_url( $args['feed_image'] ) . "\" style=\"border: none;\"$alt$title" . ' />';
    				else
    					$link .= $name;
    
    				$link .= '</a>';
    
    				if ( empty( $args['feed_image'] ) )
    					$link .= ')';
    			}
    
    			if ( $args['optioncount'] )
    				$link .= '('. $author->post_count . ')';
    
    		}
    
    		if ( ! ( $author->post_count == 0 && $args['hide_empty'] ) && 'list' == $args['style'] )
    			$return .= $link . '</div></section><hr class="separator">';
    		else if ( ! $args['hide_empty'] )
    			$return .= $link . ', ';
    	}
    
    	$return = trim( $return, ', ' );
    
    	if ( ! $args['echo'] )
    		return $return;
    	echo $return;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Author list order by last name’ is closed to new replies.