I found two bits of code. One gets me posts NOT older than a month the other bit gets me a list of authors and their custom fields, names, etc.
Can someone please help me integrate the two. One runs in the wordpress loop with a custom query and the other is a foreach (all stuff I don’t know much of). How can I get the two to work together.
Thanks for any help.
<?php
$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);
}
$authors = array();
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->ID);
if(!empty($hide_empty)) {
$numposts = count_user_posts($user->ID);
if($numposts < 1) continue;
}
$authors[] = (array) $user;
}
<?php
foreach($authors as $author) {
$display_name = $author['data']->display_name;
$main_profile = get_the_author_meta('mainProfile', $author['data']->ID);
$hover_profile = get_the_author_meta('hoverProfile', $author['data']->ID);
$author_profile_url = get_author_posts_url($author['ID']);
?>
<div class="da-author">
<div class="original-image">
<img src="<?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}?>
Loop:
<?php
$args = array(
'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() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<a href="<?php echo the_permalink(); ?>"><?php echo get_the_title(); ?></a>
<?php }} ?>
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.