Hide All Courses in particular Course Category

Home Forums Legacy Support Support queries Other issues Hide All Courses in particular Course Category

Viewing 15 posts - 1 through 15 (of 46 total)
  • Author
    Posts
  • #237208
    Zatakk
    Spectator
    Hi I want to hide courses which belong to a particular course category. I badly need it. Instead of hiding one by one each course I want to be able to select one category and hide it.   Most Urgent !!   Regards Shailendra R
    #237311
    logan
    Member
    Hello, add this code in your customizer.php function logan_filter_pre_get_posts( $query ) { if ( ! is_singular() && $query->is_main_query() ) { $query->set( 'post__not_in', array( 123, 11, 12, 13 ) ); } } add_action( 'pre_get_posts', 'logan_filter_pre_get_posts' ); add you post/page/course id in array.
    #237685
    Zatakk
    Spectator
    Thats not working . Anyway this can be easily done by Vibe Options => Hide Course from Directory. My query is for hiding all courses which belong to a particular course category !! Pls help    
    #237732
    Veronica
    Moderator
    hey have a look on this tip: https://www.wpbeginner.com/wp-tutorials/how-to-exclude-a-category-from-your-wordpress-homepage/ try these. for the code, use course category id with minus (-) sign. this should work
    #237801
    Zatakk
    Spectator
    Hi This is for post category.  And it seems to work for post category but is not working for course category. I used "course-cat " instead of 'cat' in the code given in above link.   Pls help  
    #237805
    Zatakk
    Spectator
    Seems this was already asked earlier a couple of years before https://wplms.io/support/forums/topic/hide-content-from-course-category/     
    #237880
    Anshuman Sahu
    Keymaster
    this is possible.we will share the code to do it. Please provide some time . Please ping back for reminder
    #237957
    Zatakk
    Spectator
    Hi Alex Just a friendly reminder :)
    #237983
    logan
    Member

    Hello,

    add this code in your customizer.php

    add_filter('wplms_carousel_course_filters','wplms_exlude_courses_directroy_cc',99); add_filter('wplms_grid_course_filters','wplms_exlude_courses_directroy_cc',99); add_filter('vibe_editor_filterable_type','wplms_exlude_courses_directroy_cc',99); add_filter('bp_course_wplms_filters','wplms_exlude_courses_directroy_cc',99); add_filter('vibe_related_courses','wplms_exlude_courses_directroy_cc',99); function wplms_exlude_courses_directroy_cc($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=vibe_get_option('hide_courses'); 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; } } $args = 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 ) ) ); $query = new WP_Query( $args ); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); if(!empty($args['post__not_in'])){ $args['post__not_in'][] = get_the_ID(); }else{ $args['post__not_in'] = array(get_the_ID()); } endwhile; endif; wp_reset_postdata();   } return $args; }  
    #238080
    Zatakk
    Spectator
    Hi
    1. I copied the code as it is.

    2. All courses are hidden

    3. Where should I give the input ?

    4. I have only added the "slug" however, Adding any or many slugs is not helping !!

      Pls help

    #238083
    Zatakk
    Spectator
    This is the status as shown in the pic http://prnt.sc/qhwgko  
    #238168
    Diana
    Participant
    This reply has been marked as private.
    #238314
    Zatakk
    Spectator
    Hi Any Luck
    #238422
    Diana
    Participant
    This reply has been marked as private.
    #238716
    Zatakk
    Spectator
    Hi There
Viewing 15 posts - 1 through 15 (of 46 total)
  • The topic ‘Hide All Courses in particular Course Category’ is closed to new replies.