admin管理员组

文章数量:1287884

i am using the wp_list_authors function as the following:

<?php wp_list_authors( array(
'show_fullname' => 'true',
'orderby'       => 'display_name',
'order'         => 'ASC'
)) ?> 

However this shows the authors by firstname + lastname I want to switch that so it shows the users lastname + firstname.

I cant figure out how can i use the get_user_meta in the function.

It is possible or should I use something else than wp_list_authors?

i am using the wp_list_authors function as the following:

<?php wp_list_authors( array(
'show_fullname' => 'true',
'orderby'       => 'display_name',
'order'         => 'ASC'
)) ?> 

However this shows the authors by firstname + lastname I want to switch that so it shows the users lastname + firstname.

I cant figure out how can i use the get_user_meta in the function.

It is possible or should I use something else than wp_list_authors?

Share Improve this question asked Sep 13, 2021 at 10:41 Simó TamásSimó Tamás 175 bronze badges 4
  • Could you include the rest of the code? how are you outputing the name? include the foreach or for loop that you used. – Buttered_Toast Commented Sep 13, 2021 at 10:44
  • @Buttered_Toast wp_list_authors() does the outputting. – Jacob Peattie Commented Sep 13, 2021 at 10:45
  • @Buttered_Toast as Jacob mentiones wp_list_authors() does the outputting. – Simó Tamás Commented Sep 13, 2021 at 10:47
  • Was to quick to comment, my mistake. You are right, never used the function before so I assumed it return a array, after reading the documentation I see that it outputs by default. – Buttered_Toast Commented Sep 13, 2021 at 10:50
Add a comment  | 

1 Answer 1

Reset to default 1

What you want is not supported by wp_list_authors(). To output them the way you want you will need to use get_users() and display them yourself.

$authors = get_users(
    array(
        'orderby' => 'display_name',
        'order'   => 'ASC'
    )
);

foreach ( $authors as $author ) {
    echo esc_html( $author->last_name . ' ' . $author->first_name );
}

You can wrap the output in elements as needed, and pass $author->ID to get_user_meta() if you need any metadata. You can get a link to the author archive using get_author_posts_url().

本文标签: user metaCombining wplistauthors with getusermeta