Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
function my_pre_user_query( $query ) {
$where = get_posts_by_author_sql( 'post' ) . " AND MONTH(post_date) = " . date( 'm', strtotime( '-1 month' ) );
$query->query_from = str_replace( get_posts_by_author_sql( 'post' ), $where, $query->query_from );
$query->query_where .= " AND post_count > 0 ";
$query->query_limit .= " LIMIT 5 ";
}
function my_magic_loop() {
// Get last month's top authors.
add_action( 'pre_user_query', 'my_pre_user_query' );
$top_authors = new WP_User_Query( array(
'orderby' => 'post_count',
'fields' => 'ID',
) );
remove_action( 'pre_user_query', 'my_pre_user_query' );
// Get last month's top authors' posts.
$top_posts = new WP_Query( array(
'post_type' => 'post',
'author' => implode( ',', $top_authors->get_results() ),
'monthnum' => date( 'm', strtotime( '-1 month' ) ),
) );
// Boom!
if ( $top_posts->have_posts() ) {
while ( $top_posts->have_posts() ) {
$top_posts->the_post();
// ...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.