Last active
December 30, 2015 22:49
-
-
Save corypina/7896291 to your computer and use it in GitHub Desktop.
A Popular Topics query for bbPress. The built in widget will show either 1) recent topics, or 2) topics with the most replies. This queries topics with a minimum number of replies, whose most recent activity ("freshness") is more recent than a variable date (e.g., "1 month ago").
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Create, then reformat a timestamp for as far back as you want the query to go. | |
'-1 months' = 1 month ago */ | |
$date = strtotime('-1 months'); | |
$noearlier = date('Y-m-d G:i:s', $date); | |
/* Build the meta arguments */ | |
$metaargs = array( | |
array( 'key' => '_bbp_reply_count', | |
/* At least three replies */ | |
'value' => '3', | |
'compare' => '>=',), | |
array( 'key' => '_bbp_last_active_time', | |
/* Last activity no further back than the variable */ | |
'value' => $noearlier, | |
'compare' => '>=', | |
'type' => 'DATE',) | |
); | |
/* Create the query */ | |
$query = new WP_Query( array( | |
'posts_per_page' => 5, | |
'post_type' => 'topic', | |
'orderby' => 'title', | |
'order' => 'DESC', | |
'meta_query' => $metaargs, | |
)); | |
/* Printing the list items */ | |
if ( $query->have_posts()) : | |
?><ul><?php | |
while ($query->have_posts()) : $query->the_post(); | |
?><li><a class="bbp-forum-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php | |
endwhile; | |
?></ul><?php | |
endif; | |
/* Restore original Post Data */ | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment