$course_key = 'course_' . $post->ID; if (is_user_logged_in()) { $user_id = get_current_user_id(); $user_meta = get_user_meta($user_id, $post->ID, true); if (isset($user_meta)) { $course_key = 'course_' . $user_id . '_' . get_the_ID(); } } $result = wp_cache_get($course_key, 'course_loop'); } else { $result = false; } if (false === $result) { ob_start(); if (function_exists('bp_course_item_view')) { bp_course_item_view(); } $result = ob_get_clean(); } if ($cache_duration) { wp_cache_set($course_key, $result, 'course_loop', $cache_duration); } echo $result; ?> <?php } ?> </ul>
function course_filter() { global $bp; $args = array('post_type' => BP_COURSE_CPT); if (isset($_POST['filter'])) { $filter = $_POST['filter']; switch ($filter) { case 'popular': $args['orderby'] = 'meta_value'; $args['meta_key'] = 'vibe_students'; break; case 'newest': $args['orderby'] = 'date'; break; case 'rated': $args['orderby'] = 'meta_value'; $args['meta_key'] = 'average_rating'; break; case 'alphabetical': $args['orderby'] = 'title'; $args['order'] = 'ASC'; break; case 'start_date': $args['orderby'] = 'meta_value'; $args['meta_key'] = 'vibe_start_date'; $args['meta_type'] = 'DATE'; $args['order'] = 'ASC'; break; default: $args['orderby'] = ''; break; } } if (isset($_POST['search_terms']) && $_POST['search_terms']) { $args['search_terms'] = $_POST['search_terms']; } if (isset($_POST['page'])) { $args['paged'] = $_POST['page']; } if (isset($_POST['scope']) && $_POST['scope'] == 'personal') { $uid = get_current_user_id(); $args['meta_query'] = array(array('key' => $uid, 'compare' => 'EXISTS')); } if (isset($_POST['scope']) && $_POST['scope'] == 'instructor') { $uid = get_current_user_id(); $args['instructor'] = $uid; } if (isset($_POST['extras'])) { $extras = json_decode(stripslashes($_POST['extras'])); $course_categories = array(); $course_levels = array(); $course_location = array(); $type = array(); if (is_array($extras)) { foreach ($extras as $extra) { switch ($extra->type) { case 'course-cat': $course_categories[] = $extra->value; break; case 'free': $type = $extra->value; break; case 'instructor': $instructors[] = $extra->value; break; case 'level': $course_levels[] = $extra->value; break; case 'location': $course_location[] = $extra->value; break; case 'start_date': $start_date = $extra->value; break; case 'end_date': $end_date = $extra->value; break; } } } $args['tax_query'] = array(); if (count($course_categories)) { $args['tax_query']['relation'] = 'AND'; $args['tax_query'][] = array('taxonomy' => 'course-cat', 'terms' => $course_categories, 'field' => 'slug'); } if (count($instructors)) { $args['author__in'] = $instructors; } if ($type) { switch ($type) { case 'free': $args['meta_query']['relation'] = 'AND'; $args['meta_query'][] = array('key' => 'vibe_course_free', 'value' => 'S', 'compare' => '='); break; case 'paid': $args['meta_query']['relation'] = 'AND'; $args['meta_query'][] = array('key' => 'vibe_course_free', 'value' => 'H', 'compare' => '='); break; } } if (!empty($start_date)) { $args['meta_query']['relation'] = 'AND'; $args['meta_query'][] = array('key' => 'vibe_start_date', 'value' => $start_date, 'compare' => '>='); } if (!empty($end_date)) { $args['meta_query']['relation'] = 'AND'; $args['meta_query'][] = array('key' => 'vibe_start_date', 'value' => $end_date, 'compare' => '<='); } if (count($course_levels)) { $args['tax_query']['relation'] = 'AND'; $args['tax_query'][] = array('taxonomy' => 'level', 'field' => 'slug', 'terms' => $course_levels); } if (count($course_location)) { $args['tax_query']['relation'] = 'AND'; $args['tax_query'][] = array('taxonomy' => 'location', 'field' => 'slug', 'terms' => $course_location); } } $loop_number = vibe_get_option('loop_number'); isset($loop_number) ? $loop_number : ($loop_number = 5); $args['per_page'] = $loop_number; ?> <?php do_action('bp_before_course_loop'); ?> <?php if (bp_course_has_items($args)) { ?> <div id="pag-top" class="pagination "> <div class="pag-count" id="course-dir-count-top"> <?php bp_course_pagination_count(); ?> </div> <div class="pagination-links" id="course-dir-pag-top"> <?php bp_course_item_pagination(); ?> </div> </div> <?php do_action('bp_before_directory_course_list'); $cookie = urldecode($_POST['cookie']); if (stripos($cookie, 'bp-course-list=grid')) { $class = 'grid'; } ?> <ul id="course-list" class="item-list <?php echo apply_filters('wplms_course_directory_list', $class); ?> " role="main"> <?php while (bp_course_has_items()) { bp_course_the_item(); ?> <?php global $post; $cache_duration = vibe_get_option('cache_duration'); if (!isset($cache_duration)) { $cache_duration = 86400; } if ($cache_duration) { $course_key = 'course_' . $post->ID; if (is_user_logged_in()) { $user_id = get_current_user_id(); $user_meta = get_user_meta($user_id, $post->ID, true); if (isset($user_meta)) { $course_key = 'course_' . $user_id . '_' . get_the_ID(); } } $result = wp_cache_get($course_key, 'course_loop'); } else { $result = false; } if (false === $result) { ob_start(); bp_course_item_view(); $result = ob_get_clean(); } if ($cache_duration) { wp_cache_set($course_key, $result, 'course_loop', $cache_duration); } echo $result; ?> <?php } ?> </ul> <?php do_action('bp_after_directory_course_list'); ?> <div id="pag-bottom" class="pagination"> <div class="pag-count" id="course-dir-count-bottom"> <?php bp_course_pagination_count(); ?> </div> <div class="pagination-links" id="course-dir-pag-bottom"> <?php bp_course_item_pagination(); ?> </div> </div> <?php } else { ?> <div id="message" class="info"> <p><?php _e('No Courses found.', 'vibe'); ?> </p> </div> <?php } ?> <?php do_action('bp_after_course_loop'); die; }