Author List page: Exclude based on last post date

WordPress itself does not store this info directly in database… yet you have some elegant options:

you can hook into “publish post” and update list of “active users” when someone posts his/her published, you can store this information then in options table in serialized array. In this array you can have list of authors and when they published their last post, which you use for picking recent active…

OR

You can just edit this one php template, you have to loop through all authors and separate them accordingly in foreach loop before you print output… for speeding up page you can store filtered users or whole content of page in wordpress transient, where you can easily cashe arrays or plan html output, see wordpress transient api: http://codex.wordpress.org/Transients_API

OR

You can simply skip autor whose last post is older than 6 months like this:

<?php
// Arguments to pass to get_users
// ************* $args = array( 'orderby' => 'post_count', 'order' => 'DSC', 'who' => 'authors' );
// Query for the users
$authors = get_users('orderby=post_count&order=DSC'); //&role=contributor ?>
<h4 style="padding-top:20px;">Writers</h4>  
<?php
// Loop through all the users, printing all of their posts as we go
foreach ( $authors as $author ) {

    // Set up a Loop, querying for all of the current user's posts
    $args = array( 'author' => $author->ID, 'posts_per_page' => 1 );
    $posts = query_posts($args);

    if (6 < (date('n',(time() - strtotime($posts[0]->post_date)))))
        continue; //skips this autor as long as his last post is older than 6 months, be aware that this check uses date function.

 ?>
            <a name="<?php echo $author->user_nicename; ?>"></a>
            <div class="author-posts-wrapper" id="author-<?php echo $author->ID; ?>-posts-wrapper">
                <div class="author-avatar" id="author-<?php echo $author->ID; ?>-avatar">
                    <?php echo get_avatar( $author->ID, 96 ); ?>
                </div>
                <div class="author-posts" id="author-<?php echo $author->ID; ?>-posts">
                    <h2><a href="https://wordpress.stackexchange.com/questions/71657/<?php echo get_author_posts_url( $author->ID ); ?>"><?php echo $author->display_name; ?></a></h2>

    <?php if ( have_posts() ) :  ?>
                <ul class="author-post-list" id="author-<?php echo $author->ID; ?>-post-list">
        <?php while ( have_posts() ) : the_post(); // Print whatever we want for each post - for now the title ?>
                    <div class="author-descrip" style="padding-bottom:2px;">
                        <?php the_author_meta("description"); ?></div>
          <p style="font-size:14px; color:#555;"><strong><?php the_author_posts(); ?> articles written. Most recent: <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></strong></p>
          <p style="padding-top:8px;">
            <?php if(get_the_author_meta('user_url')): ?>
                <?= get_the_author_meta('user_url') ?>
            <?php endif; ?>
          </p>
        <?php endwhile; ?>
                </ul><!-- #author-post-list -->
    <?php else: ?>
                    <p style="font-style:italic;">This author has not yet published any posts</p>
    <?php endif; ?>
                </div><!-- #author-posts -->
            </div><!-- #author-posts-wrapper -->
      <br />
<?php } // End looping over all users ?>

Leave a Comment