Browse: Home / Snippets /

Get all course IDs


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_all_course_ids() {
	$query_args = array(
		'post_type'			=>	'sfwd-courses',
		'post_status'		=>	'publish',
		'fields'			=>	'ids',
		'orderby'			=>	'title',
		'order'				=>	'ASC',
		'nopaging'			=>	true	// Turns OFF paging logic to get ALL courses

	$query = new WP_Query( $query_args );
	if ( $query instanceof WP_Query) {
		return $query->posts;