Show list of authors with latest post NOT older than a month

Your query needs to include an argument to specify the author, and would need to be inside one of your “author” Loops. In fact, I see no need to Loop over your author data twice. Once should be fine.

$display_admins = false;
$order_by = 'display_name';
$role=""; // 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all'
$hide_empty = false;

if(!empty($display_admins)) {
    $blogusers = get_users('orderby='.$order_by.'&role=".$role);
} else {
    $admins = get_users("role=administrator');
    $exclude = array();
    foreach($admins as $ad) {
        $exclude[] = $ad->ID;
    }
    $exclude = implode(',', $exclude);
    $blogusers = get_users('exclude=".$exclude."&orderby='.$order_by.'&role=".$role);
}

foreach($blogusers as $author) {
  $args =  array(
    "author' => $author->ID, // here is your author ID
    'showposts' => 1,
    'orderby' => 'date',
    'date_query' => array(
      array(
        'after' => array(
        'year'  => date( "Y" ),
        'month' => date( "m", strtotime( "-1 Months" ) ),
        'day'   => date( "t", strtotime( "-1 Months" ) ),
      ),
      'inclusive' => true,
      )
    )
  );
  $query = new WP_Query( $args );
  if ($query->have_posts()) {

    $display_name = $author->data->display_name;
    $main_profile = get_the_author_meta('mainProfile', $author->ID);
    $hover_profile = get_the_author_meta('hoverProfile', $author->ID);
    $author_profile_url = get_author_posts_url($author->ID); ?>

    <div class="da-author">

      <div class="original-image">
          <img src="https://wordpress.stackexchange.com/questions/138923/<?php echo $main_profile; ?>" alt="<?php echo $display_name; ?>">
      </div>

      <div class="hover-image">
          <a href="<?php echo $author_profile_url; ?>">
              <img src="<?php echo $hover_profile; ?>">
          </a>
      </div>

    </div><?php
    // a post Loop
    while ($query->have_posts()) {
      $query->the_post();
      the_title();
      // etc.
    }
  }
}

Leave a Comment