Support » Fixing WordPress » How to show authors by level of users and number of posts?

  • Well, hello!

    I was wondering how can I make a query that shows me for examples editor or authors info just when we have an X number of posts (for example 3 post). The idea is to show for example in the authors page all authors that have more than 3 posts as part of the staff.

    $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts.' INNER JOIN '.$wpdb->users.' ON '.$wpdb->posts.'.post_author = '.$wpdb->users.'.ID ORDER BY '.$wpdb->users.'.display_name ASC');

    What I have is this, but this only shows users with posts..
    How can I add the type of users to this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I don’t think there’s anything in the database that shows the user role directly (at least in wp_users or wp_usermeta), but user levels are still associated with the role.

    Go to the section of this link that shows “User Levels” to see how they correspond.

    You could write some of your own php code to translate the number generated from calling wp_user_level into the name associated with it.

    Maybe try calling the author inside the loop like this:

    I think you could try something like this:

    <!-- Inside the loop -->
    $userLevel = get_the_author_meta('user_level');
    if ($userLevel == '2') {
      $userRole = "Author";
      echo $userRole;

    That should give you the user role. You’ll need another if statement to only show the correct role and posts… if $userRole = author and $postcount >= 3 then print username, postcount, and role.

    The idea is to show all the writers, editor etc as part of the staff, so It won’t be inside the loop!

    Is this part of your author.php template page?

    Either way, I think you can grab wp_user_level from the usermeta table. I’m not so good with the query structure, but here’s what I pulled from my phpmyadmin query

    SELECT *
    FROM wp_usermeta
    WHERE meta_key LIKE ‘wp_user_level’
    AND meta_value LIKE ’10’

    Probably change 10 to 2 to grab “Author” only, again, see to grab the right user type and adjust your query appropriately.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to show authors by level of users and number of posts?’ is closed to new replies.