Browse: Home / Snippets /

Get all quizzes in a course

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

function learndash_get_course_quizzes( $course_id = 0 ) {
	if ( !empty( $course_id ) ) {
		$query_args = array( 
			'post_type' 		=> 	'sfwd-quiz', 
			'posts_per_page' 	=> 	-1,
			'orderby'			=>	'title',
			'order'				=>	'ASC',
			'meta_key'     		=> 'course_id',
			'meta_value'   		=> $course_id,
			'meta_compare' 		=> '=',
			// This tells WP_Query to return only the post IDs. Comment 
			// out if you want full Post object
			'fields'			=>	'ids'
		);

		$query_results = new WP_Query( $query_args );

		if ( !empty( $query_results->posts ) ) {
			return $query_results->posts;
		}
	}
}