Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peterwilsoncc/fa8d36a3dd1a7c822bb883901e836476 to your computer and use it in GitHub Desktop.
Save peterwilsoncc/fa8d36a3dd1a7c822bb883901e836476 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Remove orderby when counting comments.
*/
namespace PWCC\Test58368;
/**
* Remove orderby when counting comments.
*
* @param string[] $clauses An associative array of comment query clauses.
* @param WP_Comment_Query $query Current instance of WP_Comment_Query (passed by reference).
* @return string[] Modified $clauses.
*/
function no_comment_count_order_by( $clauses, $wp_comment_query ) {
if ( ! $wp_comment_query->query_vars['count'] ) {
return $clauses;
}
$clauses['orderby'] = '';
return $clauses;
}
add_filter( 'comments_clauses', __NAMESPACE__ . '\\no_comment_count_order_by', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment