dozent_get_course_id_by_content( int|object|null $post = null )
Get course id by course content.
Description
Course content means lecture, quiz, assignments. If we pass the content as object or just ID, it will return attached course id.
Example usage:
dozent_get_course_id_by_content( $lecture );
dozent_get_course_id_by_content( $lecture->ID );
dozent_get_course_id_by_content( $lecture_id );
Parameters
- $post
-
(int|object|null) (Optional) Object or ID
Default value: null
Return
(int)
Source
File: includes/core-functions.php
function dozent_get_course_id_by_content( $post = null ) { global $wpdb; $post = get_post( $post ); if ( empty( $post->ID ) ){ return false; } $course_id = wp_cache_get( $post->ID , 'dozent_course_id_by_content' ); if ( ! $course_id ) { $course_id = $wpdb->get_var( "SELECT post_parent FROM {$wpdb->posts} WHERE ID = {$post->post_parent} AND post_type = 'dozent_section' " ); $course_id = absint( $course_id ); wp_cache_add( $post->ID, $course_id, 'dozent_course_id_by_content' ); } return (int) $course_id; }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |