0

I want to display only Authors not any Subscriber who write blog in my website. So can you help me on this?

<?php
            //define vars from user selection
            $howManyAuthors = 10;

            //Get users and count of posts put into array 
            $authorsArray=array();
            $blogusers = get_users_of_blog();
            if ($blogusers) {
              foreach ($blogusers as $bloguser) {
                $post_count = get_usernumposts($bloguser->user_id);
                $authorsArray[$bloguser->user_id]=$post_count;
              }
              arsort($authorsArray); 
              $maxauthor = $howManyAuthors;
              $count=0;
              foreach ($authorsArray as $key => $value) {
              $count++;
                if ($count <= $maxauthor) {
                    $user = get_userdata($key); 
                    $username = $user->user_login;                          
                    $displayname = $user->display_name; 
                    $author_posts_url = get_author_posts_url($key);
                    $post_count = $value;

                      $args=array(
                        'showposts'=>1,
                        'author'=>$user->ID,
                        'caller_get_posts'=>1
                      );
                      $my_query = new WP_Query($args);
                      if( $my_query->have_posts() ) {
                        while ($my_query->have_posts()) : $my_query->the_post(); 
        ?>
 <?php
                        endwhile;
                     }
                  ?>

                <!-- end of topWriterBox -->
                <?php
            }
          }
        }
        ?>
  • Try to properly format your code. Not all loops are closed. – Ciprian Aug 24 '15 at 9:07
  • Please clean up your code, it is unreadable. Use the {} in the editor for code – Pieter Goosen Aug 24 '15 at 9:08
  • The code seems to be truncated. Check @WisdmLabs comment. – Ciprian Aug 24 '15 at 9:41
1

Use following code to get all users having role Author

$args = array(
    'role'         => 'author',
    'number'       => '10',
);

$authors = get_users( $args );

For all argument list refer this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.