WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Latest 5 authors sorted by posting date

[Resolved] Latest 5 authors sorted by posting date

  • Hi everybody!

    I need to show the latest 5 authors (actually contributors in WordPress role management) order by their latest data posts.

    I mean I have around 20 authors and I need to display only 5 authors who posted most recently!

    Anybody can help me with this?

    Thanks a lot!

Viewing 15 replies - 1 through 15 (of 20 total)
  • http://net.tutsplus.com/tutorials/wordpress/quick-tip-popular-posts-by-comment-count-sql-query-in-wordpress/

    Its not what you want but select different parts of the DB should work.

    Thanks a lot devilson. I studied your link, but Iā€™m afraid my expertise is not high enough to complete this task without more in deep explanations. šŸ™

    but Iā€™m afraid my expertise is not high enough to complete this task without more in deep explanations.

    Where do you want to display that information–in your sidebar? If so does your theme support widgets? If necessary can you install a plugin?

    Yes I can install/use a plugin or a sidebar widget.

    if you dont want it in the side bar im willing to put it to gether for you.

    Thank you devilson! I will highly apreciate if you can help me with this!

    <?php $pop = $wpdb->get_results("SELECT id, post_author, guid FROM {$wpdb->prefix}posts WHERE post_type='post' ORDER BY id DESC LIMIT 5");
    foreach($pop as $post) : ?>
    <?php $pop1 = $wpdb->get_results("SELECT user_nicename FROM {$wpdb->prefix}users");
    foreach($pop1 as $user) : ?>
    
    <li><a href="<?php echo $post->guid; ?>"><?php echo $user->user_nicename; ?></a></li>
    
    <?php endforeach; ?><?php endforeach; ?>

    That should work put it where you want it.

    It could be shorter but im still learning php.

    Edit: If it doesn’t work tell me as i built it on my local host with one user.

    Hi devilson! Thanks a lot. I tested but Iā€™m afraid it doesn’t work as it should. The code displays all my users for 5 times. šŸ™

    Hi devilson! Thanks a lot. I tested but Iā€™m afraid it doesn’t work as it should. The code displays all my users for 5 times. šŸ™

    Ill look into it.

    I found this but i doesn’t order them and im not sure how to limit the ammount it shows.

    <?php list_authors(TRUE, TRUE); ?>

    Unfortunately function list_authors will not help me in any way! šŸ™

    In that case i would use a plugin.

    <?php
    //list 5 latest authors
    $authors =  array();
    $count = 0;
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'Latest 5 authors';
      while ($my_query->have_posts() && $count < 5) : $my_query->the_post();
        $author_id=$my_query->post->post_author;
        if (!in_array($author_id,$authors)) {
          echo '<p>';
          the_author_posts_link();
          echo '</p>';
        $count++;
        $authors[]=$author_id;
        }
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thanks a lot! The code look nice but when I tried to executed it I run into this:

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 32768 bytes) in … /wp-includes/wp-db.php on line 734

    Methods for increasing the amount of memory a PHP script may consume

    1. If you have access to your PHP.ini file, change the line in PHP.ini
    If your line shows 32M try 64M:
    memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)

    2. If you don’t have access to PHP.ini try adding this to an .htaccess file:
    php_value memory_limit 64M

    3. Try adding this line to your wp-config.php file:
    define('WP_MEMORY_LIMIT', '64M');

    4. Talk to your host.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Resolved] Latest 5 authors sorted by posting date’ is closed to new replies.
Skip to toolbar