dozent_get_course_reviews( array $args = array() )
Query rating and reviews
Description
Get the courses rating and reviews results by query it from the database. The results you can filter by passing $args value as array
Example usage:
dozent_get_course_reviews( array(
'course_id' => 0,
'user_id' => 0,
's' => null, //Search term
'rating' => null,
'status' => 1,
'start' => 0,
'per_page' => 10 //per page
) );
Parameters
- $args
-
(array) (Optional) Arguments of the query
Default value: array()
Return
(object)
Source
File: includes/core-functions.php
3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 | function dozent_get_course_reviews( $args = [] ) { global $wpdb ; /** * Filter the default query parameter of dozent_get_course_reviews(); * * @since DozentLMS 1.0.0 * * @see dozent_get_course_reviews(); * * @param array $query_params Parameter of the query */ $defaults = apply_filters( 'dozent_get_course_reviews_args' , [ 'course_id' => 0, 'user_id' => 0, 's' => null, 'rating' => null, 'status' => 1, 'start' => 0, 'per_page' => dozent_show_per_page(), 'order_by' => 'DESC' , ] ); $r = wp_parse_args( $args , $defaults ); //set default start result if ( empty ( $r [ 'start' ] ) ) { $per_page = isset( $r [ 'per_page' ] ) ? $r [ 'per_page' ] : dozent_show_per_page(); if ( dozent_input_text( 'current_page' ) ) { $page = max( 1, dozent_input_text( 'current_page' ) ); } else { $page = max( 1, dozent_input_text( 'page' ) ); } $r [ 'start' ] = ( $page - 1 ) * $per_page ; } extract( $r , EXTR_SKIP ); $where = " WHERE 1 = 1 " ; if ( ! empty ( $course_id ) ) { $where .= " AND reviews.course_id = {$course_id} " ; } if ( ! empty ( $user_id ) ) { $where .= " AND reviews.user_id = {$user_id} " ; } if ( ! empty ( $s ) ) { $where .= " AND reviews.review like '%{$s}%' " ; } if ( ! empty ( $rating ) ) { $where .= " AND reviews.rating = {$rating} " ; } if ( ! empty ( $status ) && $status !== 'any' ) { $where .= " AND reviews.status = {$status} " ; } $limit_query = '' ; if ( ! empty ( $per_page ) && $per_page != '-1' ) { $limit_query = " LIMIT {$start}, {$per_page} " ; } $order = '' ; if ( ! empty ( $order_by ) ) { $order = " ORDER BY reviews.ID {$order_by} " ; } $where = apply_filters( 'dozent_get_course_reviews_where' , $where ); $count = $wpdb ->get_var( " SELECT COUNT (reviews.ID) FROM { $wpdb ->dozent_reviews} reviews LEFT JOIN { $wpdb ->users} review_author ON reviews.user_id = review_author.ID LEFT JOIN { $wpdb ->posts} course ON reviews.course_id = course.ID { $where };" ); $query = $wpdb ->get_results( " SELECT reviews.* , review_author.display_name as user_display_name, course.post_title as course_title FROM { $wpdb ->dozent_reviews} reviews LEFT JOIN { $wpdb ->users} review_author ON reviews.user_id = review_author.ID LEFT JOIN { $wpdb ->posts} course ON reviews.course_id = course.ID { $where } { $order } { $limit_query };" ); return (object) [ 'count' => (int) $count , 'results' => $query ]; } |
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |