WC_Shortcode_Products::order_by_rating_post_clauses()public staticWC 3.2.0

Order by rating.

Method of the class: WC_Shortcode_Products{}

No Hooks.

Return

Array.

Usage

$result = WC_Shortcode_Products::order_by_rating_post_clauses( $args );
$args(array) (required)
Query args.

Changelog

Since 3.2.0 Introduced.

WC_Shortcode_Products::order_by_rating_post_clauses() code WC 9.4.2

public static function order_by_rating_post_clauses( $args ) {
	global $wpdb;

	$args['where']  .= " AND $wpdb->commentmeta.meta_key = 'rating' ";
	$args['join']   .= "LEFT JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID) LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)";
	$args['orderby'] = "$wpdb->commentmeta.meta_value DESC";
	$args['groupby'] = "$wpdb->posts.ID";

	return $args;
}