Is it possible to show only one course and then show

Is it possible to show only one course and then show another only when the first course has been signed up for (whether completed or not)?

  • Ash

    Hello @AndrewTraub

    Please try the following code:

    add_action( 'pre_get_posts', 'pre_get_posts_cb' );
    function pre_get_posts_cb( $query ) {
    	$parent_course = 5;
    	$hidden_course = array( 785, 21 );
    	if( is_user_logged_in() ){
    		if ( ! is_admin() ) {
    			if( $query->get( 'post_type' ) == 'course' ){
    				$progress = new Course_Completion( $parent_course );
    				$progress->init_student_status();
    				if ( 0 >= $progress->course_progress() ) {
    					$query->set( 'post__not_in', $hidden_course );
    				}
    
    			}
    		}
    	}else{
    		$query->set( 'post__not_in', $hidden_course );
    	}
    }

    You just need to set IDs in $parent_course and $hidden_course.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash