_generate_categories_dropdown_option( array $categories, int $post_ID, int $depth )

Generate Course categories dropdown


Description

See also


Parameters

$categories

(array) (Required) Categories in array format

$post_ID

(int) (Required) Course ID

$depth

(int) (Required) current depth


Return

(string)


Source

File: includes/template-functions.php

	function _generate_categories_dropdown_option( $categories, $post_ID = 0, $depth = 0 ) {
		$output = '';

		if ( dozent_count( $categories ) ) {
			foreach ( $categories as $category_id => $category ) {
				if ( ! $category->parent ) {
					$depth = 0;
				}

				$children    = dozent_array_get( 'children', $category );
				$has_in_term = has_term( $category->term_id, 'course_category', $post_ID );

				$depth_separator = '';
				if ( $depth ) {
					for ( $depth_i = 0; $depth_i < $depth; $depth_i ++ ) {
						$depth_separator .= '-';
					}
				}

				$output .= "<option value='{$category->term_id}' " . selected( $has_in_term, true, false )
				           . " > {$depth_separator} {$category->name} </option> ";

				if ( dozent_count( $children ) ) {
					$depth ++;
					$output .= _generate_categories_dropdown_option( $children, $post_ID, $depth );
				}
			}
		}

		return $output;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.