Net Advocate Score
-1,
'post_type' => 'swift_reviews',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'swiftreviews_ratings',
'value' => $ratingVal
)
),
);
if (isset($_GET['catid']) && !empty($_GET['catid'])) {
$args_ten_stars['tax_query'][] = array(
'taxonomy' => 'swift_reviews_category',
'field' => 'term_id',
'terms' => sanitize_text_field($_GET['catid']),
);
}
$ten_stars_reveiws = new WP_Query($args_ten_stars);
$ten_stars_rating_value[] = $ten_stars_reveiws->found_posts;
}
$ten_star_data['labels'] = $chartLabels;
$data_array1 = array('data' => $ten_stars_rating_value, 'backgroundColor' => $chart_background_color, 'hoverBackgroundColor' => $chart_hover_background_color);
$ten_star_data['datasets'] = array($data_array1);
$starsData_ten = json_encode($ten_star_data);
?>
-1,
'post_type' => 'swift_reviews',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'swiftreviews_ratings',
'value' => array(0, 3),
'compare' => 'BETWEEN'
),
),
);
if (isset($_GET['catid']) && !empty($_GET['catid'])) {
$args1['tax_query'][] = array(
'taxonomy' => 'swift_reviews_category',
'field' => 'term_id',
'terms' => sanitize_text_field($_GET['catid']),
);
}
$reviews1 = get_posts($args1);
$reviews_score1 = '';
foreach ($reviews1 as $r1) {
$ratings = get_post_meta($r1->ID, 'swiftreviews_ratings', true);
$reviews_score1 = $reviews_score1 + $ratings;
}
$total_reveiw1 = count($reviews1);
wp_reset_postdata();
/* Passives */
$args2 = array(
'posts_per_page' => -1,
'post_type' => 'swift_reviews',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'swiftreviews_ratings',
'value' => array(3.5, 4),
'compare' => 'BETWEEN'
),
),
);
if (isset($_GET['catid']) && !empty($_GET['catid'])) {
$args2['tax_query'][] = array(
'taxonomy' => 'swift_reviews_category',
'field' => 'term_id',
'terms' => sanitize_text_field($_GET['catid']),
);
}
$reviews2 = get_posts($args2);
$reviews_score2 = '';
foreach ($reviews2 as $r2) {
$ratings = get_post_meta($r2->ID, 'swiftreviews_ratings', true);
$reviews_score2 = $reviews_score2 + $ratings;
}
$total_reveiw2 = count($reviews2);
wp_reset_postdata();
/* Advocates */
$args3 = array(
'posts_per_page' => -1,
'post_type' => 'swift_reviews',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'swiftreviews_ratings',
'value' => array(4.5, 5),
'compare' => 'BETWEEN'
),
),
);
if (isset($_GET['catid']) && !empty($_GET['catid'])) {
$args3['tax_query'][] = array(
'taxonomy' => 'swift_reviews_category',
'field' => 'term_id',
'terms' => sanitize_text_field($_GET['catid']),
);
}
$reviews3 = get_posts($args3);
$reviews_score3 = '';
foreach ($reviews3 as $r3) {
$ratings = get_post_meta($r3->ID, 'swiftreviews_ratings', true);
$reviews_score3 = $reviews_score3 + $ratings;
}
$total_reveiw3 = count($reviews3);
wp_reset_postdata();
$total_reveiews = $total_reveiw1 + $total_reveiw2 + $total_reveiw3;
if (!empty($total_reveiews)) {
$detractors = round((($total_reveiw1 / $total_reveiews ) * 100), 2);
$passives = round((($total_reveiw2 / $total_reveiews ) * 100), 2);
$advocates = round((( $total_reveiw3 / $total_reveiews ) * 100), 2);
}
?>
| Detractors (0-6) |
|
| Passives (7-8) |
|
| Advocates (9-10) |
|
| Total Reviews |
|