llms_get_post_parent_course( WP_Post|int $post )

Retrieve the parent course for a section, lesson, or quiz


Parameters Parameters

$post

(WP_Post|int) (Required) WP Post ID or instance of WP_Post.


Top ↑

Return Return

(LLMS_Course|null) Instance of the LLMS_Course or null.


Top ↑

Source Source

File: includes/llms.functions.core.php

917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
*/
function llms_get_post_parent_course( $post ) {
 
    $post = llms_get_post( $post );
 
    if ( ! $post || ! is_a( $post, 'LLMS_Post_Model' ) ) {
        return null;
    }
 
    /**
     * Filter the course children post types
     *
     * @since Unknown
     *
     * @param $post_type string[] Names of the post types that can be children of a course.
     */
    $post_types = apply_filters( 'llms_course_children_post_types', array( 'section', 'lesson', 'llms_quiz' ) );
    if ( ! in_array( $post->get( 'type' ), $post_types, true ) ) {
        return null;
    }
 
    /** @var LLMS_Section|LLMS_Lesson|LLMS_Quiz $post */
    return $post->get_course();


Top ↑

Changelog Changelog

Changelog
Version Description
3.6.0
3.37.14 Bail if $post is not an istance of LLMS_Post_Model. Use strict comparison.
3.17.7 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.