Addons.php
5 years ago
Admin.php
5 years ago
Ajax.php
5 years ago
Assets.php
5 years ago
Course.php
5 years ago
Course_Filter.php
5 years ago
Course_Settings_Tabs.php
5 years ago
Course_Widget.php
5 years ago
Custom_Validation.php
5 years ago
Dashboard.php
5 years ago
Delete_Enrollment_With_Order.php
5 years ago
Email.php
5 years ago
FormHandler.php
5 years ago
Frontend.php
5 years ago
Gutenberg.php
5 years ago
Instructor.php
5 years ago
Instructors_List.php
5 years ago
Lesson.php
5 years ago
Options.php
5 years ago
Post_types.php
5 years ago
Private_Course_Access.php
5 years ago
Q_and_A.php
5 years ago
Question_Answers_List.php
5 years ago
Quiz.php
5 years ago
Quiz_Attempts_List.php
5 years ago
RestAPI.php
5 years ago
Rewrite_Rules.php
5 years ago
Shortcode.php
5 years ago
Student.php
5 years ago
Students_List.php
5 years ago
Taxonomies.php
5 years ago
Template.php
5 years ago
Theme_Compatibility.php
5 years ago
Tools.php
5 years ago
Tutor.php
5 years ago
TutorEDD.php
5 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
5 years ago
Tutor_Setup.php
5 years ago
Upgrader.php
5 years ago
User.php
5 years ago
Utils.php
5 years ago
Video_Stream.php
5 years ago
Withdraw.php
5 years ago
Withdraw_Requests_List.php
5 years ago
WooCommerce.php
5 years ago
Course_Filter.php
94 lines
| 1 | <?php |
| 2 | namespace TUTOR; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) |
| 5 | exit; |
| 6 | |
| 7 | class Course_Filter{ |
| 8 | private $category = 'course-category'; |
| 9 | private $tag = 'course-tag'; |
| 10 | |
| 11 | function __construct(){ |
| 12 | add_action('wp_ajax_tutor_course_filter_ajax', array($this, 'load_listing')); |
| 13 | add_action('wp_ajax_nopriv_tutor_course_filter_ajax', array($this, 'load_listing')); |
| 14 | } |
| 15 | |
| 16 | public function load_listing(){ |
| 17 | $courses_per_page = (int) tutor_utils()->get_option('courses_per_page', 10); |
| 18 | $page = (isset($_POST['page']) && is_numeric($_POST['page']) && $_POST['page']>0) ? $_POST['page'] : 1; |
| 19 | |
| 20 | // Prepare taxonomy |
| 21 | $tax_query = array(); |
| 22 | foreach(['category', 'tag'] as $taxonomy){ |
| 23 | if(isset($_POST['tutor-course-filter-'.$taxonomy]) && count($_POST['tutor-course-filter-'.$taxonomy])>0){ |
| 24 | $tax_query[]=array( |
| 25 | 'taxonomy' => $this->$taxonomy, |
| 26 | 'field' => 'term_id', |
| 27 | 'terms' => $_POST['tutor-course-filter-'.$taxonomy], |
| 28 | 'operator' => 'IN' |
| 29 | ); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // Prepare level and price type |
| 34 | $level_price=array(); |
| 35 | foreach(['level', 'price'] as $type){ |
| 36 | if(isset($_POST['tutor-course-filter-'.$type]) && count($_POST['tutor-course-filter-'.$type])>0){ |
| 37 | $level_price[]=array( |
| 38 | 'key' => $type=='level' ? '_tutor_course_level' : '_tutor_course_price_type', |
| 39 | 'value' => $_POST['tutor-course-filter-'.$type], |
| 40 | 'compare' => 'IN' |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | $args = array( |
| 46 | 'post_type' => 'courses', |
| 47 | 'posts_per_page' => $courses_per_page, |
| 48 | 'paged' => $page |
| 49 | ); |
| 50 | |
| 51 | count($tax_query) ? $args['tax_query']=$tax_query : 0; |
| 52 | count($level_price) ? $args['meta_query']=$level_price : 0; |
| 53 | isset($_POST['keyword']) ? $args['s']=$_POST['keyword'] : 0; |
| 54 | |
| 55 | if(isset($_POST['tutor_course_filter'])){ |
| 56 | switch ($_POST['tutor_course_filter']){ |
| 57 | case 'newest_first': |
| 58 | $args['orderby']='ID'; |
| 59 | $args['order']='desc'; |
| 60 | break; |
| 61 | case 'oldest_first': |
| 62 | $args['orderby']='ID'; |
| 63 | $args['order']='asc'; |
| 64 | break; |
| 65 | case 'course_title_az': |
| 66 | $args['orderby']='post_title'; |
| 67 | $args['order']='asc'; |
| 68 | break; |
| 69 | case 'course_title_za': |
| 70 | $args['orderby']='post_title'; |
| 71 | $args['order']='desc'; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | query_posts($args); |
| 77 | |
| 78 | tutor_load_template('archive-course-init'); |
| 79 | exit; |
| 80 | } |
| 81 | |
| 82 | public function render_terms($taxonomy){ |
| 83 | $terms = get_terms( array('taxonomy' => $this->$taxonomy, 'hide_empty' => true)); |
| 84 | |
| 85 | foreach($terms as $term){ |
| 86 | ?> |
| 87 | <label> |
| 88 | <input type="checkbox" name="tutor-course-filter-<?php echo $taxonomy; ?>" value="<?php echo $term->term_id; ?>"/> |
| 89 | <?php echo $term->name; ?> |
| 90 | </label> |
| 91 | <?php |
| 92 | } |
| 93 | } |
| 94 | } |