• Resolved theomega1123

    (@theomega1123)


    Hello! I hope you are doing well.

    I wanted to ask directions in case I’m missing something, or a feature request in case this is missing.

    Im currently using Sensei shortcodes, and my intention is to display the USER courses but only those courses wich are from a specific category.

    In the docs I got to this shortcode:
    [sensei_user_courses]
    wich allows for some arguments:
    [sensei_user_courses number=”5″ order=”desc” orderby=”name” status=”complete”]

    But I would be requiring something like:
    [sensei_user_courses number=”5″ order=”desc” orderby=”name” status=”complete” category=”COURSE_CATEGORY”]

    Is there a way to achieve this? I’m willing to access the plugin’s php code if neccessary. In that case I’d like to know where to find the shortcodes definitions in the plugin directory. I’m willing to do my own code for a db table query if neccessary, I’d just need to know the table name or related stuff.

    Any help will be appreciated.
    Cheers!

Viewing 1 replies (of 1 total)
  • Hey @theomega1123,

    This feature is missing, but a workaround is to use the sensei_user_courses_query filter.

    Here’s a quick code example:

    add_filter( 'sensei_user_courses_query', 'my_filter_user_courses_query_by_category', 10, 4 );
    function my_filter_user_courses_query_by_category( $query, $user_id, $status, $query_args ) {
    	$query_args['tax_query'][] = [
    		'taxonomy' => 'course-category',
    		'field'    => 'slug',
    		'terms'    => 'test-category',  // <-- Change this to the slug of the category you want to filter by.
    	];
    
    	$learner_manager = Sensei_Learner::instance();
    	if ( 'complete' === $status ) {
    		$query = $learner_manager->get_enrolled_completed_courses_query( $user_id, $query_args );
    	} elseif ( 'active' === $status ) {
    		$query = $learner_manager->get_enrolled_active_courses_query( $user_id, $query_args );
    	} else {
    		$query = $learner_manager->get_enrolled_courses_query( $user_id, $query_args );
    	}
    
    	return $query;
    }

    You can also try out the new Course List Block. It is using the Query Loop Block underneath, so you can filter by any taxonomy out of the box.

    Hope this helps. ??

Viewing 1 replies (of 1 total)
  • The topic ‘Shortcodes – USER courses by CATEGORY’ is closed to new replies.