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

 */
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.