Last active
December 26, 2015 23:49
-
-
Save Chrico/7233135 to your computer and use it in GitHub Desktop.
Comment Filter to fetch comments from last week with new WP_Date_Query()
This file contains 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 | |
/** | |
* adding a date-filter to the comment_query to fetch comments from last week | |
* | |
* @param Array $clauses | |
* @return Array $clauses | |
*/ | |
function chrico_filter_comments_clauses_get_comments_last_week( $clauses ){ | |
$last_week = gmdate( 'W' ) - 1; | |
$query_args = array( | |
'w' => $last_week | |
); | |
$date_query = new \WP_Date_Query( $query_args, 'comment_date' ); | |
$clauses['where'] .= $date_query->get_sql(); | |
return $clauses; | |
} | |
add_filter('comments_clauses', 'chrico_filter_comments_clauses_get_comments_last_week' ); | |
$comments = get_comments(); | |
remove_filter( 'comments_clauses', 'chrico_filter_comments_clauses_get_comments_last_week' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment