Created
November 29, 2025 23:08
-
-
Save askwpgirl/327d2f266dae414d41d002107deef1ee to your computer and use it in GitHub Desktop.
Elementor Custom Query: Lessons for Current Course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Elementor Custom Query: Lessons for Current Course | |
| */ | |
| add_action( 'elementor_pro/posts/query/course_lessons', function( $query ) { | |
| // Get current course ID (assuming this runs on the single course page) | |
| $course_id = get_the_ID(); | |
| if ( ! $course_id ) { | |
| return; | |
| } | |
| // Make sure we’re only running this on the front end main query for the widget | |
| if ( ! $query->is_main_query() ) { | |
| return; | |
| } | |
| // Base args to fetch lessons | |
| $args = [ | |
| 'post_type' => 'sfwd-lessons', // adjust if your lessons CPT is different | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'orderby' => 'menu_order', | |
| 'order' => 'ASC', | |
| 'meta_query' => [ | |
| [ | |
| 'key' => 'course_id', // adjust to your LMS’s meta key | |
| 'value' => $course_id, | |
| ], | |
| ], | |
| ]; | |
| // Apply our custom args to Elementor’s query | |
| foreach ( $args as $key => $value ) { | |
| $query->set( $key, $value ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment