Home › Forums › Legacy Support › Support queries › Other issues › Hide All Courses in particular Course Category
- This topic has 45 replies, 5 voices, and was last updated 3 years, 11 months ago by Anshuman Sahu.
-
AuthorPosts
-
May 14, 2020 at 12:50 pm #259410Anshuman SahuKeymasteradd_filter('wplms_carousel_course_filters','wplms_exlude_courses_directroy1',99999); add_filter('wplms_grid_course_filters','wplms_exlude_courses_directroy1',99999); add_filter('bp_course_wplms_filters','wplms_exlude_courses_directroy1',99999); add_filter('vibe_related_courses','wplms_exlude_courses_directroy1',99999); function wplms_exlude_courses_directroy1($args){ if($args['post_type'] == 'course'){ if(isset($args['meta_query']) && is_array($args['meta_query']) && is_user_logged_in()){ $user_id=get_current_user_id(); foreach($args['meta_query'] as $query){ if(isset($query) && is_array($query)){ if($query['key'] == $user_id){ return $args; } } } } $excluded_courses =array(); $args1 = array( 'post_type' => 'course', 'tax_query' => array( array( 'taxonomy' => 'course-cat', 'field' => 'slug', //can be set to ID 'terms' => 'technology' //if field is ID you can reference by cat/term number ) ) ); $category_posts = new WP_Query($args1); if($category_posts->have_posts()) : while($category_posts->have_posts()) : $category_posts->the_post(); $excluded_courses[] = get_the_ID(); endwhile; endif; wp_reset_postdata(); if(!empty($excluded_courses) && is_array($excluded_courses) && !(isset($args['author']) || isset($args['author_name']))){ if(!empty($args['post__not_in'])){ $args['post__not_in'] = array_merge($args['post__not_in'], $excluded_courses); }else{ $args['post__not_in'] = $excluded_courses; } } } return $args; } add_filter('bp_course_total_count','hidden_courses1'); function hidden_courses1($totalcount){ $excluded_courses =array(); $args1 = array( 'post_type' => 'course', 'tax_query' => array( array( 'taxonomy' => 'course-cat', 'field' => 'slug', //can be set to ID 'terms' => 'technology' //if field is ID you can reference by cat/term number ) ) ); $category_posts = new WP_Query($args1); if($category_posts->have_posts()) : while($category_posts->have_posts()) : $category_posts->the_post(); $excluded_courses[] = get_the_ID(); endwhile; endif; wp_reset_postdata(); return $totalcount - count($excluded_courses); }
-
AuthorPosts
- The topic ‘Hide All Courses in particular Course Category’ is closed to new replies.