0

I want to display some data from an author on my loop with this code:

  • Avatar

    <?php echo get_avatar( $q->ID, 255 ); ?>
    
  • Name.

    <?php echo get_the_author_meta('display_name', $q->ID);?>
    
  • Total post.

    <?php echo 'Posts made: ' . count_user_posts( get_the_author_meta($q->ID) ); ?>
    

Full code:

 <?php 
        $number     = $count_post;
        $paged      = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $offset     = ($paged - 1) * $number;
        $users      = get_users();
        $query      = get_users('&offset='.$offset.'&number='.$number);
        $total_users = count($users);
        $total_query = count($query);
        foreach($query as $q) { ?>

 - Avatar
 <?php echo get_avatar( $q->ID, 255 ); ?>
 - Name.
  <?php echo get_the_author_meta('display_name', $q->ID);?>
 - Total post.
    <?php echo 'Posts made: ' . count_user_posts( get_the_author_meta($q->ID) ); ?>

    <?php }
 ?>

The avatar and the author's name is displayed, but the total post failed to display.

Anybody know how to resolve the problem? Really appreciate for any idea.

Regards

0

the_author_posts() doesn't accept any parameters see the following codex page for more info:

https://codex.wordpress.org/Function_Reference/the_author_posts#Parameters

* UPDATED *

Someone else had posted a VERY similar question. This should solve your problem:

Show author post count in sidebar - Variable

  • Just edited, change to <?php echo 'Posts made: ' . count_user_posts( get_the_author_meta($q->ID) ); ?> but still not work – Mailmulah Feb 26 '16 at 23:18
  • What is your $q query? Is that a post/page query or is that a user account query? – Ryan Feb 26 '16 at 23:37
  • just edit, added the full code. Please kindly check. – Mailmulah Feb 26 '16 at 23:41
  • I read the link you gave me, doesn't work for me. – Mailmulah Feb 26 '16 at 23:43
  • Do me a favor, simply echo $q->ID and let me know what it returns. That will be the first step towards solving your problem. – Ryan Feb 26 '16 at 23:49
1

Isn't it just:

<?php echo 'Posts made: ' . count_user_posts( $q->ID ); ?>

Assuming that $q->ID is your author's ID. count_user_posts()

  • just edit, added the full code. – Mailmulah Feb 26 '16 at 23:40

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.