/
categories.php
executable file
·37 lines (29 loc) · 1.23 KB
/
categories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
add_action('rest_api_init', function ($server) {
register_rest_route(STM_LMS_API, '/categories', array(
'methods' => 'GET',
'callback' => function () {
$data = array(
'categories' => array()
);
$terms = array();
$terms_all = stm_lms_get_terms_with_meta( '', 'stm_lms_course_taxonomy', ['orderby' => 'count', 'order' => 'DESC', 'number' => 10] );
if( ! empty( $terms_all ) ){
foreach ($terms_all as $term) {
$meta_value = get_term_meta( $term->term_id, 'course_app_image', true );
$color = get_term_meta( $term->term_id, 'course_color', true );
if(empty($color)) $color = null;
$term_data = array(
'id' => $term->term_id,
'name' => $term->name,
'count' => $term->count,
'color' => $color,
);
$term_data['image'] = !empty($meta_value) ? stm_lms_api_image($meta_value, 100, 100) : null;
$terms[] = $term_data;
}
}
wp_send_json($terms);
},
));
});